package com.hrbxlh.actionImpl;


import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Function;
import com.hrbxlh.dao.*;
import com.hrbxlh.enums.KnowGradeEnum;
import com.hrbxlh.enums.TeaStatisticsEnum;
import com.hrbxlh.pojo.CourseOrExpre;
import com.hrbxlh.pojo.TaskLibrary;
import com.hrbxlh.pojo.TaskLibraryVO;
import com.hrbxlh.util.*;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.tool.xml.XMLWorkerHelper;
import org.apache.log4j.LogSF;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import javax.annotation.Nullable;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.math.BigDecimal;
import java.util.*;


@Component("teaStatisticsActionImpl")
public class TeaStatisticsActionImpl {
    @Resource(name = "teaStatisticsDao")
    private TeaStatisticsDao teaStatisticsDao;

    @Resource(name="sourceDao")
    private SourceDao sourceDao;

    @Resource(name="problemDao")
    private ProblemDao problemDao;

    @Resource(name="myCourseDao")
    private MyCourseDao myCourseDao;

    @Resource(name = "memberDao")
    private MemberDao memberDao;

    @Resource(name = "loginDao")
    private LoginDao loginDao;

    @Resource(name="chapterDao")
    private ChapterDao chapterDao;

    @Resource(name="courseDao")
    private CourseDao courseDao;

    @Resource(name = "coursePowerDao")
    private CoursePowerDao coursePowerDao;

    @Resource(name = "siteDao")
    private SiteDao siteDao;
    //日志信息
    Logger logger = Logger.getLogger(TeaStatisticsActionImpl.class.getName());

    /**
     * 课程统计 ：按课程统计已学人数、正在学习人数、问题交流问题数、回答问题数、实验学习平均实长、平均成绩
     * @throws IOException
     */
    public Map<String, Object> getCouStatisticsByTeaId(Map<String,Object> parameMap,HttpServletRequest request) throws Exception {

        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            //课程总统计的对象
            Map<String, Object> totalMap = new HashMap<String, Object>();
            //获取当前登陆人的工号
            String stuorteaId = PubMethods.loginId(request);
            parameMap.put("stuorteaId", stuorteaId);
            parameMap.put("selecetRoleId",2);
            List<Map<String,Object>> memberList = memberDao.getMemberDetailById(parameMap);
            returnMap.put("courseWordMark",memberList.get(0).get("courseWordMark"));

            int startNum = pageUtil.getSqlStartPos(Integer.parseInt(String.valueOf(parameMap.get("pageNow"))), Integer.parseInt(String.valueOf(parameMap.get("pageSize"))));
            parameMap.put("startNum", startNum);

            /**按课程统计start**/
            parameMap.put("mark",2);
            //正在学习人数or已学人数（未结课的or已结课的）、问题交流问题数、回答问题数
            List<Map<String,Object>> learnStucountList = teaStatisticsDao.getLearningStuCountByTeaId(parameMap);
            //当前教师所教学生总数（按课程）
            List<Map<String,Object>> stuCountList = teaStatisticsDao.getStuCountList(parameMap);
            //查询某个教师教的学生实验时长总和（课程id集合,学生id集合为条件）
            parameMap.put("stuCountList",stuCountList);
            //查询当前登陆人教的学生
            List<Map<String,Object>> stuList = teaStatisticsDao.getStuList(parameMap);
            parameMap.put("stuList",stuList);
            if(learnStucountList.size()==0||stuCountList.size()==0||stuList.size()==0){
                returnMap.put("totalPage", 1);
                returnMap.put("pageNow", 1);
                returnMap.put("finalList", null);
                return returnMap;
            }
            List<Map<String,Object>> expreLongList = teaStatisticsDao.getExpreLongList(parameMap);
            //实验总时长
            //实验学习平均实长
            Map<String,Object> avgMap = new HashMap<String, Object>();
            avgMap.put("sumLong","sumLong");
            List<Map<String,Object>> AvgExperimentTimeList = this.pubAvgList(expreLongList,stuCountList,avgMap,1,1);
            //将（正在学习人数or已学人数（未结课的or已结课的）、问题交流问题数、回答问题数）与（实验总时长or实验学习平均实长）集合合并为AvgExperimentTimeMargeList
            List<Map<String,Object>> AvgExperimentTimeMargeList = this.mergeList(learnStucountList,AvgExperimentTimeList,1);
            //查询某个教师下所教学生成绩总和（课程id集合,学生id集合为条件）
            List<Map<String,Object>> examSumList = teaStatisticsDao.getexamSumList(parameMap);
            //平均成绩
            avgMap.put("sumsource","sumsource");
            avgMap.put("sumperexam","sumperexam");
            avgMap.put("sumexam","sumexam");
            List<Map<String,Object>> AvgExamList = this.pubAvgList(examSumList,stuCountList,avgMap,2,1);
            //考试及格率、实验报告提交率、作业提交率
            //及格率
            BigDecimal passRate = new BigDecimal(0);
            //实验报告提交率
            BigDecimal expreRate = new BigDecimal(0);
            //作业提交率
            BigDecimal taskRate = new BigDecimal(0);
            List<Map<String,Object>> finalList = new ArrayList<Map<String, Object>>();
            //一共教过多少班级 //一共教过多少人//批改实验报告数//批改作业数//课程章节数
            List<Map<String, Object>> teacherTeachMsg = teaStatisticsDao.getTeacherTeaSituation(parameMap);
            //查询通过的人数
            List<Map<String,Object>> passCountList = new ArrayList<Map<String,Object>>();
            //查询当前登陆人教的学生及格的学生数
            passCountList = teaStatisticsDao.getPassExamCount(parameMap);
            List<Map<String,Object>> passList =  this.rateList(passCountList,teacherTeachMsg,1,2);
            //查询当前登陆人教的学生及格的实验数
            parameMap.put("taskType", 2);
            parameMap.put("addTestMark",1);//取实验总的章节数
            teacherTeachMsg = teaStatisticsDao.getTeacherTeaSituation(parameMap);
            BigDecimal expreCount = new BigDecimal(0);
            List<Map<String,Object>> expreCountList = teaStatisticsDao.getPassExpreCount(parameMap);
            List<Map<String,Object>> expreList = this.rateList(expreCountList,teacherTeachMsg,1,1);
            //查询当前登陆人教的学生及格的提交作业数
            parameMap.put("taskType", 1);
            parameMap.put("addTestMark",2);//取作业总的章节数
            teacherTeachMsg = teaStatisticsDao.getTeacherTeaSituation(parameMap);
            BigDecimal taskCount = new BigDecimal(0);
            List<Map<String,Object>> taskCountList = teaStatisticsDao.getPassExpreCount(parameMap);
            List<Map<String,Object>> taskList = this.rateList(taskCountList,teacherTeachMsg,1,1);
            //将及格率、实验提交率、作业提交率集合合并为rateList
            List<Map<String,Object>> rateList = this.rateAllListOne(passList,expreList,taskList,1);
            //将AvgExperimentTimeMargeList集合与rateList与AvgExamList集合合并
            finalList = this.listAllOne(AvgExperimentTimeMargeList,rateList,AvgExamList,1);
            returnMap.put("finalList", finalList);
            /**按课程统计end**/

            /**总的课程统计start**/
            parameMap.put("mark",1);
            //正在学习人数or已学人数（未结课的or已结课的）、问题交流问题数、回答问题数
            List<Map<String,Object>> learnStucountListAll = teaStatisticsDao.getLearningStuCountByTeaId(parameMap);
            int stucount = Integer.valueOf(String.valueOf(learnStucountListAll.get(0).get("stucount")));//这个是每个课学习的人数加和但是会存在一人学习两个课，人数会计算多
            int answercount = Integer.valueOf(String.valueOf(learnStucountListAll.get(0).get("answercount")));
            //查询当前教师教的学生总数(不重复的)
            int stuAllCount = teaStatisticsDao.getStudentTotalCount(parameMap);
            totalMap.put("stucount",stuAllCount);
            totalMap.put("problemcount",learnStucountListAll.get(0).get("problemcount"));
            totalMap.put("answercount",answercount);
            //实验总时长
            List<Map<String,Object>> expreLongListAll = teaStatisticsDao.getExpreLongList(parameMap);
            BigDecimal sumExpreTime = new BigDecimal(String.valueOf(expreLongListAll.get(0).get("sumLong")));
            //当前教师所教学生总数
            List<Map<String,Object>> stuCountListAllTwo = teaStatisticsDao.getStuCountList(parameMap);
            BigDecimal stucout = new BigDecimal(String.valueOf(stuCountListAllTwo.get(0).get("stucount")));
            //平均时长calculationRate
            BigDecimal avgExpreTime = calculationRate(stucout,sumExpreTime);
            totalMap.put("avgExpreTime",avgExpreTime);
            //查询某个教师下所教学生成绩总和（课程id集合,学生id集合为条件）
            List<Map<String,Object>> examSumListAll = teaStatisticsDao.getexamSumList(parameMap);
            //平均总成绩
            BigDecimal avgSource = calculationRate(stucout,new BigDecimal(String.valueOf(examSumListAll.get(0).get("sumsource"))));
            //平均平时成绩
            BigDecimal avgPerexam = calculationRate(stucout,new BigDecimal(String.valueOf(examSumListAll.get(0).get("sumperexam"))));
            //平均考试成绩
            BigDecimal avgExam = calculationRate(stucout,new BigDecimal(String.valueOf(examSumListAll.get(0).get("sumexam"))));
            totalMap.put("avgSource",avgSource);
            totalMap.put("avgPerexam",avgPerexam);
            totalMap.put("avgExam",avgExam);
             //一共教过多少人//批改实验报告数//批改作业数//课程章节数
            List<Map<String, Object>> teacherTeachMsgAll = teaStatisticsDao.getTeacherTeaSituation(parameMap);
            //一共教过多少人
            BigDecimal teachStuNum = new BigDecimal(String.valueOf(teacherTeachMsgAll.get(0).get("teachStuNum")));
            //批改实验报告数
            BigDecimal checkTestNum = new BigDecimal(String.valueOf(teacherTeachMsgAll.get(0).get("checkTestNum")));
            //批改作业数
            BigDecimal checkHomeworkNum = new BigDecimal(String.valueOf(teacherTeachMsgAll.get(0).get("checkHomeworkNum")));
            //课程章节数总数
            BigDecimal chapterSum = new BigDecimal(0);
            //教授的总人数*总章节（作业）数
            BigDecimal homeCheckCount = new BigDecimal(0);
            //教授的总人数*总章节（实验）数
            BigDecimal testCheckCount = new BigDecimal(0);
            //提交作业or实验报告数submitHomeCount
            parameMap.put("taskType",1);
            parameMap.put("addTestMark",2);
            teacherTeachMsgAll = teaStatisticsDao.getTeacherTeaSituation(parameMap);
            chapterSum = new BigDecimal(String.valueOf(teacherTeachMsgAll.get(0).get("chapterSum")));//作业章节总数
            homeCheckCount = stucout.multiply(chapterSum);
            Map<String,Object> submitMap = teaStatisticsDao.getSubmitHomeOrTestCount(parameMap);
            //提交的作业数
            BigDecimal submitHomeCout = new BigDecimal(String.valueOf(submitMap.get("submitHomeCount")));
            parameMap.put("taskType",2);
            parameMap.put("addTestMark",1);
            teacherTeachMsgAll = teaStatisticsDao.getTeacherTeaSituation(parameMap);
            chapterSum = new BigDecimal(String.valueOf(teacherTeachMsgAll.get(0).get("chapterSum")));//实验章节总数
            testCheckCount = stucout.multiply(chapterSum);
            submitMap = teaStatisticsDao.getSubmitHomeOrTestCount(parameMap);
            //提交的实验报告数
            BigDecimal submitTestCout = new BigDecimal(String.valueOf(submitMap.get("submitHomeCount")));
            //作业批改概率（批改作业数/提交的作业数）
            BigDecimal checkHomeRate = calculationRate(submitHomeCout,checkHomeworkNum);
            //实验报告批改概率（批改实验报告数/提交的实验报告数）
            BigDecimal checkTestRate = calculationRate(submitTestCout,checkTestNum);
            totalMap.put("checkHomeRate",checkHomeRate);
            totalMap.put("checkTestRate",checkTestRate);
            //作业提交率（（提交作业数）/（教授的总人数*总章节（作业）数））
            BigDecimal homeRate = calculationRate(homeCheckCount,submitHomeCout);
            //实验报告提交率（（提交实验报告数）/（教授的总人数*总章节（作业）数））
            BigDecimal testRate = calculationRate(testCheckCount,submitTestCout);
            totalMap.put("homeRate",homeRate);
            totalMap.put("testRate",testRate);
            //及格率(成绩大于60的人数/教授的总人数)
            //查询当前登陆人教的学生及格的学生数
            List<Map<String,Object>> passCountListAll = teaStatisticsDao.getPassExamCount(parameMap);
            BigDecimal passCount = new BigDecimal(String.valueOf(passCountListAll.get(0).get("sumcount")));
            BigDecimal passTotalRate = calculationRate(stucout,passCount);
            totalMap.put("passTotalRate",passTotalRate);
            //注册时间
            Date registerTime = (Date) memberList.get(0).get("registerTime");
            totalMap.put("registerTime",registerTime);
            //排课周期
            Map<String,Object> relationMap = teaStatisticsDao.getRelationTime(parameMap);
            String startTime = String.valueOf(relationMap.get("startTime"));
            String endTime = String.valueOf(relationMap.get("endTime"));
            totalMap.put("startTime",startTime);
            totalMap.put("endTime",endTime);
            //排课节数
            int relationCount = Integer.valueOf(String.valueOf(relationMap.get("relationCount")));
            totalMap.put("relationCount",relationCount);
            //教授课程数量
            int teachCourseCount = learnStucountList.size();
            totalMap.put("teachCourseCount",teachCourseCount);
            //教授课程时长
            Map<String,Object> stayTimeMap = loginDao.getStayTime(parameMap);
            BigDecimal stayTime = new BigDecimal(String.valueOf(stayTimeMap.get("stayTime"))).setScale(2,BigDecimal.ROUND_HALF_UP);
            totalMap.put("stayTime",stayTime);
            returnMap.put("totalMap",totalMap);
            /**总的课程统计end**/

            /**总的课程统计上面那个图strat**/

            //教学活跃度：学习人数stucount、实验平均时长avgExpreTime(秒)、问题交流回复数answercount、作业批改率checkHomeRate、实验报告批改率checkTestRate<======>共100分，平均每个部分是20分
            int learnSource = getDimensionSource(new BigDecimal(stucount),50,100,150,1);
            int timeSource = getDimensionSource(avgExpreTime,10*3600,20*3600,30*3600,1);
            int answerReplatSource = getDimensionSource(new BigDecimal(answercount),5,10,15,1);
            int homeCheckRateSource = getDimensionSource(checkHomeRate,0.3,0.5,0.8,1);
            int testCheckRateSource = getDimensionSource(checkTestRate,0.3,0.5,0.8,1);
            int activitySource = learnSource+timeSource+answerReplatSource+homeCheckRateSource+testCheckRateSource;
            returnMap.put("activitySource",activitySource);
            //教学成绩：平时成绩、考试成绩、总成绩avgSource
            returnMap.put("teachSource",avgSource);
            //教学周期：注册时间registerTime、排课周期startTime-endTime、排课节数relationCount、教授课程数量teachCourseCount、教授课程时长stayTime
            long nowTimeSeconds = PubMethods.getTimeSeconds(PubMethods.getNowTime(new Date(),1)) ;//获取当前时间的毫秒数
            long registerTimeSeconds = PubMethods.getTimeSeconds(PubMethods.getNowTime(registerTime,1));//注册时间毫秒数
            long registerChaSeconds = nowTimeSeconds-registerTimeSeconds;
            int registerSource = getDimensionSource(new BigDecimal(registerChaSeconds),registerChaSeconds*3600*24*365,(registerChaSeconds*3600*24*365)*3,(registerChaSeconds*3600*24*365)*5,1);
            long startTimeSeconds = PubMethods.getTimeSeconds(startTime+" 00:00:00");
            long endTimeSeconds = PubMethods.getTimeSeconds(endTime+" 00:00:00");
            long chaTimeSeconds = endTimeSeconds-startTimeSeconds;
            int weekTimeSource = getDimensionSource(new BigDecimal(chaTimeSeconds),chaTimeSeconds*3600*24*365,(chaTimeSeconds*3600*24*365)*3,(chaTimeSeconds*3600*24*365)*5,1);
            int relationCountSource = getDimensionSource(new BigDecimal(relationCount),50,100,150,1);
            int teachCourseCountSource = getDimensionSource(new BigDecimal(teachCourseCount),2,4,6,1);
            int stayTimeSource = getDimensionSource(stayTime,50,100,150,1);
            int cycleSource = registerSource+weekTimeSource+relationCountSource+teachCourseCountSource+stayTimeSource;
            returnMap.put("cycleSource",cycleSource);
            //教学成果：及格率passTotalRate、作业提交率homeRate、实验报告提交率testRate
            int passTotalRateSource = getDimensionSource(passTotalRate,0.3,0.5,0.8,2);
            int homeRateSource = getDimensionSource(homeRate,0.3,0.5,0.8,2);
            int testRateSource = getDimensionSource(testRate,0.3,0.5,0.8,2);
            int achievementsSource = passTotalRateSource+homeRateSource+testRateSource;
            returnMap.put("achievementsSource",achievementsSource);

            /**总的课程统计上面那个图end**/


            //计算总页数
            /*parameMap.put("pageNow",0);
            //当前教师所教学生总数（按课程）
            List<Map<String,Object>> stuCountListAll = teaStatisticsDao.getStuCountList(parameMap);
            int totalPage = pageUtil.getTotalPage(stuCountListAll, Integer.parseInt(String.valueOf(parameMap.get("pageSize"))));*/
            returnMap.put("totalPage", 1);
            returnMap.put("pageNow", Integer.parseInt(String.valueOf(parameMap.get("pageNow"))));

            //查询图标
            String[] keysArray = {"tomcatUrl", "project_name","server_address"};
            Map<String, Object> urlmap = ConfigFileUtil.getFileMessage("UtilFile.properties", keysArray);
            Map<String,Object> iconMap = siteDao.getSchoolIconDetail();
            String schoolIconUrl = "";
            int mark=0;
            if(iconMap!=null&&iconMap.size()!=0){
                schoolIconUrl  = String.valueOf(urlmap.get("server_address"))+String.valueOf(urlmap.get("project_name"))+"upload/images"+"/"+String.valueOf(iconMap.get("schoolIcon"));
                mark = Integer.parseInt(String.valueOf(iconMap.get("mark")));
            }
            returnMap.put("schoolIconUrl",schoolIconUrl);
            returnMap.put("mark",mark);

            /* //问题交流问题数
            List<Map<String,Object>> problemCountList = problemDao.getProblemCountByTeaId(parameMap);
            returnMap.put("problemCountList", problemCountList);
            //回答问题数
            List<Map<String,Object>> answerCountList = problemDao.getAnswerCountByByTeaId(parameMap);
            returnMap.put("answerCountList", answerCountList);*/
        } catch (Exception e) {
            throw e;
        }
        return returnMap;
    }

    //获取各个维度每个部分应该得到的分数
    private int getDimensionSource(BigDecimal param,double a,double b,double c,int mark){
        int finalSource = 0;
        if(mark==1){
            if(param.compareTo(new BigDecimal(a))==0||param.compareTo(new BigDecimal(a))==-1){
                //是<=a 《==》给5分
                finalSource = 5;
            }if(param.compareTo(new BigDecimal(a))==1&&(param.compareTo(new BigDecimal(b))==0||param.compareTo(new BigDecimal(b))==-1)){
                //是a<x<=b 《==》给10分
                finalSource = 10;
            }if(param.compareTo(new BigDecimal(b))==1&&(param.compareTo(new BigDecimal(c))==0||param.compareTo(new BigDecimal(c))==-1)){
                //是b<x<=c 《==》给15分
                finalSource = 15;
            }if(param.compareTo(new BigDecimal(c))==1){
                //是>c 《==》给20分
                finalSource = 20;
            }
        }if(mark==2){
            //每块是33分
            if(param.compareTo(new BigDecimal(a))==0||param.compareTo(new BigDecimal(a))==-1){
                //是<=a 《==》给5分
                finalSource = 5;
            }if(param.compareTo(new BigDecimal(a))==1&&(param.compareTo(new BigDecimal(b))==0||param.compareTo(new BigDecimal(b))==-1)){
                //是a<x<=b 《==》给10分
                finalSource = 13;
            }if(param.compareTo(new BigDecimal(b))==1&&(param.compareTo(new BigDecimal(c))==0||param.compareTo(new BigDecimal(c))==-1)){
                //是b<x<=c 《==》给15分
                finalSource = 23;
            }if(param.compareTo(new BigDecimal(c))==1){
                //是>c 《==》给20分
                finalSource = 33;
            }
        }

        return finalSource;
    }

    /**
     * 课程详情--课程统计 ：按课程统计已学人数、正在学习人数、问题交流问题数、回答问题数、实验学习平均实长、平均成绩
     * @throws IOException
     */
    public Map<String, Object> getCouStatisticsByTeaIdDetail(Map<String,Object> parameMap,HttpServletRequest request) throws Exception {

        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            //获取当前登陆人的工号
            String stuorteaId = PubMethods.loginId(request);
            parameMap.put("stuorteaId", stuorteaId);

            //正在学习人数or已学人数（未结课的or已结课的）、问题交流问题数、回答问题数
            List<Map<String,Object>> learnStucountList = teaStatisticsDao.getLearningStuClassByCouId(parameMap);

            //当前教师所教学生总数（按课程）
            List<Map<String,Object>> stuCountList = teaStatisticsDao.getStuClassListByCouId(parameMap);
            //查询某个教师教的学生实验时长总和（课程id集合,学生id集合为条件）
            parameMap.put("stuCountList",stuCountList);
            //查询当前登陆人教的学生
            List<Map<String,Object>> stuList = teaStatisticsDao.getStuList(parameMap);
            parameMap.put("stuList",stuList);
            List<Map<String,Object>> expreLongList = teaStatisticsDao.getExpreLongListByCouId(parameMap);
            //实验总时长
            //实验学习平均实长
            Map<String,Object> avgMap = new HashMap<String, Object>();
            avgMap.put("sumLong","sumLong");
            List<Map<String,Object>> AvgExperimentTimeList = this.pubAvgList(expreLongList,stuCountList,avgMap,1,2);
            //将（正在学习人数or已学人数（未结课的or已结课的）、问题交流问题数、回答问题数）与（实验总时长or实验学习平均实长）集合合并为AvgExperimentTimeMargeList
            List<Map<String,Object>> AvgExperimentTimeMargeList = this.mergeList(learnStucountList,AvgExperimentTimeList,2);
            //查询某个教师下所教学生成绩总和（课程id集合,学生id集合为条件）
            List<Map<String,Object>> examSumList = teaStatisticsDao.getexamSumListByCouId(parameMap);
            //平均成绩
            avgMap.put("sumsource","sumsource");
            avgMap.put("sumperexam","sumperexam");
            avgMap.put("sumexam","sumexam");
            List<Map<String,Object>> AvgExamList = this.pubAvgList(examSumList,stuCountList,avgMap,2,2);
            //考试及格率、实验报告提交率、作业提交率
            //及格率
            BigDecimal passRate = new BigDecimal(0);
            //实验报告提交率
            BigDecimal expreRate = new BigDecimal(0);
            //作业提交率
            BigDecimal taskRate = new BigDecimal(0);
            List<Map<String,Object>> finalList = new ArrayList<Map<String, Object>>();
            //一共教过多少班级 //一共教过多少人//批改实验报告数//批改作业数
            List<Map<String, Object>> teacherTeachMsg = teaStatisticsDao.getDetailTeacherTeaSituation(parameMap);
            //查询通过的人数
            List<Map<String,Object>> passCountList = new ArrayList<Map<String,Object>>();
            //查询当前登陆人教的学生及格的学生数
            passCountList = teaStatisticsDao.getDetailPassExamCount(parameMap);
            List<Map<String,Object>> passList =  this.rateList(passCountList,teacherTeachMsg,2,2);
            //查询当前登陆人教的学生的实验数
            parameMap.put("taskType", 2);
            parameMap.put("addTestMark",1);
            BigDecimal expreCount = new BigDecimal(0);
            teacherTeachMsg = teaStatisticsDao.getDetailTeacherTeaSituation(parameMap);
            List<Map<String,Object>> expreCountList = teaStatisticsDao.getDetailPassExpreCount(parameMap);
            List<Map<String,Object>> expreList = this.rateList(expreCountList,teacherTeachMsg,2,1);
            //查询当前登陆人教的学生的提交作业数
            parameMap.put("taskType", 1);
            parameMap.put("addTestMark",1);
            BigDecimal taskCount = new BigDecimal(0);
            teacherTeachMsg = teaStatisticsDao.getDetailTeacherTeaSituation(parameMap);
            List<Map<String,Object>> taskCountList = teaStatisticsDao.getDetailPassExpreCount(parameMap);
            List<Map<String,Object>> taskList = this.rateList(taskCountList,teacherTeachMsg,2,1);
            //将及格率、实验提交率、作业提交率集合合并为rateList
            List<Map<String,Object>> rateList = this.rateAllListOne(passList,expreList,taskList,2);
            //将AvgExperimentTimeMargeList集合与rateList与AvgExamList集合合并
            finalList = this.listAllOne(AvgExperimentTimeMargeList,rateList,AvgExamList,2);
            returnMap.put("finalList", finalList);
        } catch (Exception e) {
            throw e;
        }
        return returnMap;
    }

    /**
     * 学生统计 ：学生的实验总时间、提问问题数、回答问题数、提交作业数、实验报告数。实验笔记数、平时成绩、考试成绩、总成绩、学生姓名、
     * 课程名
     * @throws IOException
     */
    public Map<String, Object> getStuStatisticsByTeaId(Map<String,Object> parameMap,HttpServletRequest request) throws Exception {

        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            //获取当前登陆人的工号
            String stuorteaId = PubMethods.loginId(request);
            parameMap.put("stuorteaId", stuorteaId);
            int startNum = pageUtil.getSqlStartPos(Integer.parseInt(String.valueOf(parameMap.get("pageNow"))), Integer.parseInt(String.valueOf(parameMap.get("pageSize"))));
            parameMap.put("startNum", startNum);
            //查询当前教师所教的班级集合
            List<Map<String,Object>> classList = teaStatisticsDao.getAllClassListByTeaId(parameMap);
            returnMap.put("classList",classList);
            //查询当前登陆人所教的学生及对应的课程
            List<Map<String,Object>> stuAndCouList = teaStatisticsDao.getStuAndCouList(parameMap);
            if(stuAndCouList.size()==0){
                returnMap.put("finalList",null);
                returnMap.put("pageNow", 1);
                returnMap.put("totalPage", 1);
                return returnMap;
            }
            //通过stuAndCouList中的人员id和课程id为条件查询实验总时长
            parameMap.put("stuAndCouList",stuAndCouList);
            List<Map<String,Object>> expreLongList = teaStatisticsDao.getExpreStuList(parameMap);
            //通过stuAndCouList中的人员id和课程id为条件查询问题和回答合并在一起
            List<Map<String,Object>> proAndAnswerList = teaStatisticsDao.getProAndAnswerStuList(parameMap);
            //通过stuAndCouList中的人员id和课程id为条件查询提交作业数or实验报告数
            parameMap.put("taskType",1);
            List<Map<String,Object>> taskList = teaStatisticsDao.geTaskOrExperStuList(parameMap);
            parameMap.put("taskType",2);
            List<Map<String,Object>> expreList = teaStatisticsDao.geTaskOrExperStuList(parameMap);
            //通过stuAndCouList中的人员id和课程id为条件查询实验笔记数
            List<Map<String,Object>> expreNotList = teaStatisticsDao.geExperNotStuList(parameMap);
            //通过stuAndCouList中的人员id和课程id为条件查询平时成绩、考试成绩、总成绩、学生姓名、
            List<Map<String,Object>> sourceList = teaStatisticsDao.geSourceStuList(parameMap);
            //将集合变成Map
            Map<String,Map<String,Object>> expreLongMap = this.returnMap(expreLongList);
            Map<String,Map<String,Object>> proAndAnswerMap = this.returnMap(proAndAnswerList);
            Map<String,Map<String,Object>> taskMap = this.returnMap(taskList);
            Map<String,Map<String,Object>> expreMap = this.returnMap(expreList);
            Map<String,Map<String,Object>> expreNotMap = this.returnMap(expreNotList);
            Map<String,Map<String,Object>> sourceMap = this.returnMap(sourceList);
            //将结果拼在一起
            List<Map<String,Object>> finalList = this.getFinalList(stuAndCouList,expreLongMap,proAndAnswerMap,taskMap,expreMap,expreNotMap,sourceMap);
            returnMap.put("finalList",finalList);
            returnMap.put("pageNow", parameMap.get("pageNow"));
            parameMap.put("pageNow",0);
            List<Map<String,Object>> stuAndCouListAll = teaStatisticsDao.getStuAndCouList(parameMap);
            int totalPage = pageUtil.getTotalPage(stuAndCouListAll, Integer.parseInt(String.valueOf(parameMap.get("pageSize"))));
            returnMap.put("totalPage", totalPage);

        } catch (Exception e) {
            throw e;
        }
        return returnMap;
    }

    /**
     * 教师端--学生学习报告列表
     * @throws IOException
     */
    public Map<String, Object> getAllStuReportByTeaId(Map<String,Object> parameMap,HttpServletRequest request) throws Exception {

        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            //搜索框对象
            Map<String,Object> subObject = new HashMap<>();
            if(parameMap.get("userName")!=null&&!String.valueOf(parameMap.get("userName")).equals("")){
                subObject.put("userName",parameMap.get("userName"));
            } if(parameMap.get("classId")!=null&&!String.valueOf(parameMap.get("classId")).equals("")&&Integer.parseInt(String.valueOf(parameMap.get("classId")))!=0){
                subObject.put("classId",parameMap.get("classId"));
            } if(parameMap.get("stuorteaId")!=null&&!String.valueOf(parameMap.get("stuorteaId")).equals("")){
                subObject.put("stuorteaId",parameMap.get("stuorteaId"));
            }
            returnMap.put("subObject",subObject);
            //获取当前登陆人(教师)的工号
            String teaId = PubMethods.loginId(request);
            parameMap.put("teaId", teaId);
            int startNum = pageUtil.getSqlStartPos(Integer.parseInt(String.valueOf(parameMap.get("pageNow"))), Integer.parseInt(String.valueOf(parameMap.get("pageSize"))));
            parameMap.put("startNum", startNum);
            List<Map<String,Object>> stuList = teaStatisticsDao.getAllStuReportByTeaId(parameMap);
            returnMap.put("stuList", stuList);
            returnMap.put("pageNow", parameMap.get("pageNow"));
            parameMap.put("pageNow",0);
            List<Map<String,Object>> stuListAll = teaStatisticsDao.getAllStuReportByTeaId(parameMap);
            int totalPage = pageUtil.getTotalPage(stuListAll, Integer.parseInt(String.valueOf(parameMap.get("pageSize"))));
            returnMap.put("totalPage", totalPage);
            //查询当前教师所教班级列表
            parameMap.put("stuorteaId", teaId);
            List<Map<String,Object>> classList = teaStatisticsDao.getAllClassListByTeaId(parameMap);
            returnMap.put("classList",classList);
            returnMap.put("result","success");
            returnMap.put("failMsg","");
        } catch (Exception e) {
            returnMap.put("result","fail");
            returnMap.put("failMsg","获取失败");
            throw e;
        }
        return returnMap;
    }


    /**
     * 学生统计--详情 ：点击详情显示每门课程的实验时长、课程成绩分数、当前课程排名。每个章节的课程成绩（平时成绩）、班级平均成绩、实验时长、该实验章节平均时长。
     * @throws IOException
     */
    public Map<String, Object> getStuStatisticsDetailByStuId(Map<String,Object> parameMap,HttpServletRequest request) throws Exception {

        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            //获取当前登陆人(教师)的工号
            String teaId = PubMethods.loginId(request);
            parameMap.put("teaId", teaId);
            int startNum = pageUtil.getSqlStartPos(Integer.parseInt(String.valueOf(parameMap.get("pageNow"))), Integer.parseInt(String.valueOf(parameMap.get("pageSize"))));
            parameMap.put("startNum", startNum);
            //查询学生--点击详情显示每门课程的实验时长、课程成绩分数、当前课程排名。每个章节的课程成绩（平时成绩）、班级平均成绩、实验时长、该实验章节平均时长。
            List<Map<String,Object>> stuChapterSourceList = teaStatisticsDao.getStuChapterSourceList(parameMap);
            if(stuChapterSourceList==null||stuChapterSourceList.size()==0){
                returnMap.put("finalList", null);
                returnMap.put("userName", null);
                returnMap.put("className", null);
                returnMap.put("courseName", null);
                returnMap.put("pageNow", parameMap.get("pageNow"));
                parameMap.put("pageNow",0);
                return returnMap;
            }
            //查询当前学生所在班级当前课程每章节的总分数
            List<Map<String,Object>> stuAllChapterSource = teaStatisticsDao.getAllChapterSourceList(parameMap);
            //将集合转换成map
            Map<String, Map<String,Object>> stuAllChapterSourceMap = this.returnStuMap(stuAllChapterSource);
            //查询当前学生所在班级的人数
            BigDecimal stuCount = teaStatisticsDao.getStuCount(parameMap);
            //查询当前学生每章节实验时长
            List<Map<String,Object>> stuChapterExperLongList = teaStatisticsDao.getStuChapterExperLongList(parameMap);
            //查询当前学生所在班级当前课程每章节的总实验时长
            List<Map<String,Object>> stuAllChapterExperLongList = teaStatisticsDao.getAllStuChapterExperLongList(parameMap);
            //将集合转换成map
            Map<String, Map<String,Object>> stuChapterExperAllLongMap = this.returnStuMap(stuAllChapterExperLongList);
            Map<String, Map<String,Object>> stuChapterExperLongMap = this.returnStuMap(stuChapterExperLongList);
            //循环集合--将结果拼在一起
            List<Map<String,Object>> finalList = this.getStuDetailFinalList(stuChapterSourceList,stuAllChapterSourceMap,stuChapterExperAllLongMap,stuCount,stuChapterExperLongMap);
            returnMap.put("finalList", finalList);
            returnMap.put("userName", finalList.get(0).get("userName"));
            returnMap.put("className", finalList.get(0).get("className"));
            returnMap.put("courseName", finalList.get(0).get("courseName"));
            returnMap.put("pageNow", parameMap.get("pageNow"));
            parameMap.put("pageNow",0);
            List<Map<String,Object>> stuChapterSourceAll = teaStatisticsDao.getStuChapterSourceList(parameMap);
            int totalPage = pageUtil.getTotalPage(stuChapterSourceAll, Integer.parseInt(String.valueOf(parameMap.get("pageSize"))));
            returnMap.put("totalPage", totalPage);
        } catch (Exception e) {
            throw e;
        }
        return returnMap;
    }

    /**
     * 学生报告
     * param:学生id
     * @return 统计学生的实验总时间、提问问题数、回答问题数、提交作业数、实验报告数。实验笔记数、平时成绩、考试成绩、总成绩、学生姓名、专业、院系、课程名
     * @throws IOException
     */
    public Map<String, Object> getStuReportDetailByStuId(Map<String,Object> parameMap,HttpServletRequest request) throws Exception {

        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            //获取当前登陆人的工号
            String stuorteaId = PubMethods.loginId(request);
            parameMap.put("teaId",stuorteaId);

            /***这部分是按课程统计的start***/
            parameMap.put("mark",2);
            //通过学号查询某个学生每个课程的实验时长
            List<Map<String,Object>> expreLongList = teaStatisticsDao.getExpreByStuId(parameMap);
            //通过学号查询某个学生每个课程的问题和回答合并在一起
            List<Map<String,Object>> proAndAnswerList = teaStatisticsDao.getProAndAnswerByStuId(parameMap);
            //通过学号查询某个学生每个课程的提交作业数or实验报告数
            parameMap.put("taskType",1);
            List<Map<String,Object>> taskList = teaStatisticsDao.geTaskOrExperByStuId(parameMap);
            //查询每个课程所拥有作业的章节数
            parameMap.put("addTestMark",2);
            List<Map<String,Object>> homeChapterList = chapterDao.chapterCountBySid(parameMap);
            parameMap.put("taskType",2);
            List<Map<String,Object>> expreList = teaStatisticsDao.geTaskOrExperByStuId(parameMap);
            //查询每个课程所拥有实验的章节数
            parameMap.put("addTestMark",1);
            List<Map<String,Object>> testChapterList = chapterDao.chapterCountBySid(parameMap);
            //通过学号查询某个学生每个课程的实验笔记数
            List<Map<String,Object>> expreNotList = teaStatisticsDao.geExperNotByStuId(parameMap);
            //通过学号查询某个学生每个课程的平时成绩、考试成绩、总成绩、学生姓名、
            List<Map<String,Object>> sourceList = teaStatisticsDao.geSourceByStuId(parameMap);

            //阅读课件次数 or 实验次数（进入实验环境次数）
            List<Map<String,Object>> readorcomList = courseDao.getMyCourseCourseOrExpreCount(parameMap);
            //进入每个课程的次数
            List<Map<String,Object>> comCourseList = teaStatisticsDao.getSelecCourseCount(parameMap);
            //在线考试次数(系统自动提交的不算)
            parameMap.put("automaticMark",0);
            List<Map<String,Object>> onlineExamCountList =teaStatisticsDao.getOnlineExamCount(parameMap);
            //将集合变成Map
            Map<String,Map<String,Object>> proAndAnswerMap = this.returnMap(proAndAnswerList);
            Map<String,Map<String,Object>> taskMap = this.returnMap(taskList);
            Map<String,Map<String,Object>> expreMap = this.returnMap(expreList);
            Map<String,Map<String,Object>> expreNotMap = this.returnMap(expreNotList);
            Map<String,Map<String,Object>> sourceMap = this.returnMap(sourceList);
            Map<String,Map<String,Object>> homeChapterMap = this.returnMap(homeChapterList);
            Map<String,Map<String,Object>> testChapterMap = this.returnMap(testChapterList);
            Map<String,Map<String,Object>> readorcomMap = this.returnMap(readorcomList);
            Map<String,Map<String,Object>> comCourseMap = this.returnMap(comCourseList);
            Map<String,Map<String,Object>> onlineExamMap = this.returnMap(onlineExamCountList);
            //查询课程所属的全部知识点
            parameMap.put("list",expreLongList);
            List<Map<String,Object>> knowpointAllList = teaStatisticsDao.getKnowpointListBycouId(parameMap);
            //去重后的全部知识点
            List<Map<String,Object>> knowpointAllNoRepeatList = noRepeatList(knowpointAllList);
            //通过当前学生所学课程id和学号查出当前学生所学课程对应作业信息
            parameMap.put("taskType",1);
            List<Map<String,Object>> taskTwoList = teaStatisticsDao.getAllTaskByStuIdAndCouId(parameMap);
            List<TaskLibraryVO> finalKnowList = new ArrayList<>();
            List<Map<String,Object>> knowStuList = new ArrayList<>();
            if(taskTwoList==null || taskTwoList.size()==0){
                //说明学生没有交作业，则所有的知识点全部为错误
                //将等级加进去
                for(int i=0;i<knowpointAllNoRepeatList.size();i++){
                    TaskLibraryVO taskLibrary = new TaskLibraryVO();
                    taskLibrary.setGrade(KnowGradeEnum.BAD.getCode());
                    taskLibrary.setChapterId(Integer.valueOf(String.valueOf(knowpointAllNoRepeatList.get(i).get("chapterId"))));
                    taskLibrary.setTasklibrary_knowpoint(String.valueOf(knowpointAllNoRepeatList.get(i).get("tasklibrary_knowpoint")));
                    taskLibrary.setCourseId(Integer.valueOf(String.valueOf(knowpointAllNoRepeatList.get(i).get("courseId"))));
                    finalKnowList.add(taskLibrary);
                }
            }else{
                //查出当前学生所学课程对应作业信息===对应的知识点信息（这里面有重复数据）
                parameMap.put("taskTwoList",taskTwoList);
                knowStuList = teaStatisticsDao.getKnowpointListByChapterId(parameMap);
                //将知识点去重
                List<Map<String,Object>> knowpointList = noRepeatList(knowStuList);
                //将学生提交的作业与对应的知识点进行错误与否的对比
                Map<String,Object> finalKnowMap = RightOrWorng(taskTwoList,knowStuList,knowpointList,knowpointAllNoRepeatList);
                finalKnowList  = (List<TaskLibraryVO>) finalKnowMap.get("knowFinalList");
            }
            //将结果拼在一起
            List<Map<String,Object>> finalList = this.getStuReportFinalList(expreLongList,proAndAnswerMap,taskMap,expreMap,expreNotMap,
                    sourceMap,finalKnowList,homeChapterMap,testChapterMap,readorcomMap,comCourseMap,onlineExamMap);
            returnMap.put("finalList",finalList);
            //查询学生的基本信息
            parameMap.put("selecetRoleId",1);
            List<Map<String,Object>> memberList = memberDao.getMemberDetailById(parameMap);
            returnMap.put("memDetail",memberList.get(0));
            returnMap.put("result","success");
            returnMap.put("failMsg","");

            /***这部分是按课程统计的end***/


            /***这部分所有课程的统计（总的）start***/
            parameMap.put("mark",1);
            //通过学号查询某个学生每个课程的实验时长
            List<Map<String,Object>> expreLongListAll = teaStatisticsDao.getExpreByStuId(parameMap);
            //通过学号查询某个学生每个课程的问题和回答合并在一起
            List<Map<String,Object>> proAndAnswerListAll = teaStatisticsDao.getProAndAnswerByStuId(parameMap);
            //通过学号查询某个学生每个课程的提交作业数or实验报告数
            parameMap.put("taskType",1);
            List<Map<String,Object>> taskListAll = teaStatisticsDao.geTaskOrExperByStuId(parameMap);
            parameMap.put("taskType",2);
            List<Map<String,Object>> expreListAll = teaStatisticsDao.geTaskOrExperByStuId(parameMap);
            //通过学号查询某个学生每个课程的实验笔记数
            List<Map<String,Object>> expreNotListAll = teaStatisticsDao.geExperNotByStuId(parameMap);
            //通过学号查询当前学生登陆次数
            long loginCount = loginDao.loginCoutBySid(parameMap);
            //通过学号查询当前学生学习的课程所有的章节数
            parameMap.put("addTestMark",2);
            long homeChapterCount = Long.parseLong(String.valueOf((chapterDao.chapterCountBySid(parameMap)).get(0).get("chapterCount")));
            //计算作业提交率（当前学生提交的作业数/总的章节数且保留两位小数） avgSource = sumSource.divide(stuCount,2,BigDecimal.ROUND_HALF_UP);
            BigDecimal homeworRate = calculationRate(new BigDecimal(homeChapterCount),new BigDecimal(String.valueOf(taskListAll.get(0).get("taskorexprecount"))));
            //计算实验报告率（当前学生提交的实验报告数/总的章节数且保留两位小数）
            parameMap.put("addTestMark",1);
            long testChapterCount = Long.parseLong(String.valueOf((chapterDao.chapterCountBySid(parameMap)).get(0).get("chapterCount")));
            BigDecimal exprementRate = calculationRate(new BigDecimal(testChapterCount),new BigDecimal(String.valueOf(expreListAll.get(0).get("taskorexprecount"))));
            //通过学号查询某个学生总成绩为及格的课程个数
            List<Map<String,Object>> sourcePassCount = teaStatisticsDao.geSourceByStuId(parameMap);
            //及格的课程个数
            BigDecimal passCount  = new BigDecimal(String.valueOf(sourcePassCount.get(0).get("sumPassCount")));
            //学生所学的总的课程个数
            BigDecimal couseAllCount = new BigDecimal(sourceList.size());
            //计算考试及格率（考试及格的课程数/总的课程数）
            BigDecimal passRate = calculationRate(couseAllCount,passCount);
            //在线考试次数
            parameMap.put("automaticMark",0);
            long onlineExamCount = Long.parseLong(String.valueOf(teaStatisticsDao.getOnlineExamCount(parameMap).get(0).get("onlineExamCount")));
            //选课次数
            parameMap.put("couSelectMark",2);
            long coutSelectCount = teaStatisticsDao.getCouSelectCout(parameMap);
            //进入课程次数
            long comCourseCount = Long.parseLong(String.valueOf(teaStatisticsDao.getSelecCourseCount(parameMap).get(0).get("comCourseCount")));
            //阅读课件次数 or 实验次数（进入实验环境次数）
            List<Map<String,Object>> readorcomListAll = courseDao.getMyCourseCourseOrExpreCount(parameMap);
            //将查询结果合并在一起最后的Map
            Map<String,Object> statisticsMap = new HashMap<>();
            statisticsMap.put("onlineExamCount",onlineExamCount);
            statisticsMap.put("coutSelectCount",coutSelectCount);
            statisticsMap.put("comCourseCount",comCourseCount);
            statisticsMap.put("passRate",passRate);
            statisticsMap.put("exprementRate",exprementRate);
            statisticsMap.put("homeworRate",homeworRate);
            statisticsMap.put("loginCount",loginCount);
            statisticsMap.put("exprenotecount",expreNotListAll.get(0).get("exprenotecount"));
            statisticsMap.put("exprecount",expreListAll.get(0).get("taskorexprecount"));
            statisticsMap.put("taskcount",taskListAll.get(0).get("taskorexprecount"));
            statisticsMap.put("problemcount",proAndAnswerListAll.get(0).get("problemcount"));
            statisticsMap.put("answercount",proAndAnswerListAll.get(0).get("answercount"));
            statisticsMap.put("sumtime",expreLongListAll.get(0).get("sumtime"));
            statisticsMap.put("readCourseCount",readorcomListAll.get(0).get("readCourseCount"));
            statisticsMap.put("comExpreCount",readorcomListAll.get(0).get("comExpreCount"));
            /***这部分所以课程的统计（总的）end***/
            returnMap.put("statisticsMap",statisticsMap);


            /**数据能力的统计start**/
            //获取能力列表信息
            List<Map<String, Object>> coursePowerList = coursePowerDao.getCoursePowerDetail(parameMap);
            //查询各个能力对应的课程
            List<Map<String,Object>> allCoursePowerList = coursePowerDao.getAllReCoursePowerList(parameMap);
            //将每个能力对应的课程放在一起
            List<Map<String,Object>> relcopoListAllOne = getRelCoPoListOne(coursePowerList,allCoursePowerList);
            //求relcopoList与expreLongListTwo两个集合的交集---得到最终的能力与其对应的课程集合
            List<Map<String,Object>> relcopoListAllTwo = getRelcopoListAll(relcopoListAllOne,taskMap,parameMap);
            //计算每个能力值
            List<Map<String,Object>> finalRelCoPoListAll = getRelcopoListAllTwo(relcopoListAllTwo,parameMap);
            returnMap.put("finalRelCoPoListAll",finalRelCoPoListAll);
            //循环能力值，看当前学生适合什么职位
           String comment = getComment(finalRelCoPoListAll);
           returnMap.put("comment",comment);
            /**数据能力的统计end**/

            //查询图标
            String[] keysArray = {"tomcatUrl", "project_name","server_address"};
            Map<String, Object> urlmap = ConfigFileUtil.getFileMessage("UtilFile.properties", keysArray);
            Map<String,Object> iconMap = siteDao.getSchoolIconDetail();
            String schoolIconUrl = "";
            int mark=0;
            if(iconMap!=null&&iconMap.size()!=0){
                schoolIconUrl  = String.valueOf(urlmap.get("server_address"))+String.valueOf(urlmap.get("project_name"))+"upload/images"+"/"+String.valueOf(iconMap.get("schoolIcon"));
                mark = Integer.parseInt(String.valueOf(iconMap.get("mark")));
            }
            returnMap.put("schoolIconUrl",schoolIconUrl);
            returnMap.put("mark",mark);

        } catch (Exception e) {
            returnMap.put("result","fail");
            returnMap.put("failMsg","获取失败");
            throw e;
        }
        return returnMap;
    }

    //获取集合中最大的能力值<===>推出适合的岗位
    public String getComment(List<Map<String,Object>> finalRelCoPoListAll){
        double maxPowerSource = 0;
        String powerName = "";
        String comment = "";
        for(int i=0;i<finalRelCoPoListAll.size();i++){
            BigDecimal powerSource = new BigDecimal(String.valueOf(finalRelCoPoListAll.get(i).get("powerSource")));
            if(maxPowerSource<Double.parseDouble(String.valueOf(powerSource))){
                maxPowerSource = Double.parseDouble(String.valueOf(powerSource));
                powerName = String.valueOf(finalRelCoPoListAll.get(i).get("powerName"));
            }
        }
        if(powerName.equals("数据认知能力")){
            comment = "数据采集工程师、大数据研发工程师";
        } if(powerName.equals("数据处理能力")){
            comment = "数据清洗工程师、大数据研发工程师";
        } if(powerName.equals("数据管理能力")){
            comment = "大数据研发工程师";
        } if(powerName.equals("数据分析挖掘能力")){
            comment = "数据分析与挖掘工程师、数据建模工程师";
        } if(powerName.equals("数据呈现能力")){
            comment = "大数据可视化工程师";
        } if(powerName.equals("数据运维")){
            comment = "大数据运维工程师";
        }
        return comment;
    }

    //计算每个能力值
    List<Map<String,Object>> getRelcopoListAllTwo( List<Map<String,Object>> relcopoListAllTwo,Map<String,Object> paramMap){
        try {
            for(int i=0;i<relcopoListAllTwo.size();i++){
                List<Map<String,Object>> courseList = new ArrayList<>();
                List<CourseOrExpre> relcopoList = (List<CourseOrExpre>) relcopoListAllTwo.get(i).get("relcopoList");
                for (int j=0;j<relcopoList.size();j++){
                    //课程对应的权重
                    BigDecimal courseWidth = new BigDecimal(relcopoList.get(j).getWidth()).setScale(2,BigDecimal.ROUND_HALF_UP);
                    //课程实验对应的权重
                    BigDecimal expreWidth = new BigDecimal(relcopoList.get(j).getExpreWidth()).setScale(2,BigDecimal.ROUND_HALF_UP);
                    //课程考试对应的权重
                    BigDecimal examWidth = new BigDecimal(relcopoList.get(j).getExamWidth()).setScale(2,BigDecimal.ROUND_HALF_UP);
                    //课程作业对应的权重
                    BigDecimal homeworkWidth = new BigDecimal(relcopoList.get(j).getHomeworkWidth()).setScale(2,BigDecimal.ROUND_HALF_UP);
                    //课的值和课对应的map对象
                    Map<String,Object> courseMap = new HashMap<>();
                    paramMap.put("courseId",relcopoList.get(j).getCourseId());
                    paramMap.put("taskType",1);
                   //等实验报告有输入分数的时候在用这个，现在暂时用的是评价设置那有的分数作为实验报告的实际分数
                   //通过课程id查询课程所有的章节作业or实验报告实际的总分数
                    Map<String,Object> execSourceMap = teaStatisticsDao.getexecSourceTaskByCouId(paramMap);
                     /*BigDecimal testExceSource = getSource(execSourceMap,"actualSumSource");*///(这个是查章节中数据1实验 2作业)
                    //这个课共有多少章节
                    int chapterCount = Integer.parseInt(String.valueOf(execSourceMap.get("chapterCount")));
                    //实验报告实际总分数---评价设置优的分数*章节总数==实际总分数数
                    BigDecimal testExceSource = relcopoList.get(j).getExcellent().multiply(new BigDecimal(chapterCount)).setScale(2,BigDecimal.ROUND_HALF_UP);
                    //通过课程id和学生id和教师id查询当前学生作业or实验报告得分
                    Map<String,Object> allSourceMap = teaStatisticsDao.getAllSourceTaskByStuIdAndCouId(paramMap);
                    //学生作业总分
                    BigDecimal homeworkSource =getSource(allSourceMap,"taskSoruce");
                    paramMap.put("taskType",2);
                    allSourceMap = teaStatisticsDao.getAllSourceTaskByStuIdAndCouId(paramMap);
                    //学生实验报告总分
                    BigDecimal testSource = getSource(allSourceMap,"taskSoruce");
                    execSourceMap = teaStatisticsDao.getexecSourceTaskByCouId(paramMap);
                    BigDecimal homeworkExceSource = getSource(execSourceMap,"actualSumSource");

                    //通过课程id和学生id查询考试成绩
                    paramMap.put("teastaticMark",1);//标识用哪个sql
                    Map<String,Object> sourceMap = sourceDao.getExamBySidAndCourseId(paramMap);
                    //考试总成绩
                    BigDecimal sumSource = getSource(sourceMap,"examSource");
                    //计算每门课程值(（学生作业总分/作业实际总分）*100*权重+（学生实验报告总分/实验报告实际总分）*100*权重+考试总成绩*权重)!(b.compareTo(BigDecimal.ZERO)==0)
                    BigDecimal courseSource = new BigDecimal(0);
                    BigDecimal homeWorkSource = new BigDecimal(0);
                    BigDecimal expreSource = new BigDecimal(0);
                    BigDecimal examSource = new BigDecimal(0);
                    if(relcopoList.get(j).getOpenClassState()!=0){
                        //说明此课程已经开课有对应的课程值及能力值，反之没有都为0
                        examSource = sumSource.multiply(examWidth);
                        if(!(homeworkExceSource.compareTo(BigDecimal.ZERO)==0)&&!(homeworkSource.compareTo(BigDecimal.ZERO)==0)){
                            homeWorkSource = (homeworkSource.divide(homeworkExceSource,10,BigDecimal.ROUND_HALF_UP)).multiply(new BigDecimal(100)).multiply(homeworkWidth).setScale(2,BigDecimal.ROUND_HALF_UP);
                        }
                        if(!(testExceSource.compareTo(BigDecimal.ZERO)==0)&&!(testSource.compareTo(BigDecimal.ZERO)==0)){
                            expreSource = ((testSource.divide(testExceSource,10,BigDecimal.ROUND_HALF_UP)).multiply(new BigDecimal(100)).multiply(expreWidth)).setScale(2,BigDecimal.ROUND_HALF_UP);
                        }
                        courseSource = homeWorkSource.add(expreSource).add(examSource).setScale(2,BigDecimal.ROUND_HALF_UP);
                    }
                    courseMap.put("courseSource",courseSource);
                    courseMap.put("courseWidth",courseWidth);
                    courseList.add(courseMap);
                }

                //计算每个能力值
                BigDecimal powerSource = new BigDecimal(0);
                for(int k=0;k<courseList.size();k++){
                    powerSource = powerSource.add(new BigDecimal(String.valueOf(courseList.get(k).get("courseSource"))).multiply(new BigDecimal(String.valueOf(courseList.get(k).get("courseWidth"))))).setScale(2,BigDecimal.ROUND_HALF_UP);
                }
                relcopoListAllTwo.get(i).put("powerSource",powerSource);
            }

        }catch (Exception e){
            e.printStackTrace();
        }
        return relcopoListAllTwo;
    }

    //判断对象是否为空
    public BigDecimal getSource(Map<String,Object> sourceMap,String str){
        BigDecimal sumSource = new BigDecimal(0);
        if(sourceMap!=null&&sourceMap.size()!=0){
            sumSource = new BigDecimal(String.valueOf(sourceMap.get(str)));
        }
        return sumSource;
    }

    //求relcopoList与expreLongListTwo两个集合的交集
    public List<Map<String,Object>> getRelcopoListAll(List<Map<String,Object>> relcopoListAllOne, Map<String,Map<String,Object>> taskMap,Map<String,Object> paramMap ) throws Exception {
        String stuorteaId = String.valueOf(paramMap.get("stuorteaId"));
        //求relcopoList与expreLongListTwo两个集合的交集
        for (int i=0;i<relcopoListAllOne.size();i++){
            List<CourseOrExpre> relcopoList = (List<CourseOrExpre>) relcopoListAllOne.get(i).get("relcopoList");
            for(int j=0;j<relcopoList.size();j++){
                String key = stuorteaId+"_"+String.valueOf(relcopoList.get(j).getCourseId());
                Map<String,Object> taskValue = taskMap.get(key);
                //通过课程id和学生id查询当前学生这个课时哪个老师教，优的分值是多少
                paramMap.put("courseId",relcopoList.get(j).getCourseId());
                Map<String,Object> exceSourceMap = teaStatisticsDao.getExcellentSourceByCouId(paramMap);
                if(taskValue!=null&&taskValue.size()!=0){
                    //说明当前学生学这个能力的某个课程了，且这个课程属于已开课状态
                    relcopoList.get(j).setOpenClassState(TeaStatisticsEnum.START.getCode());
                    if(exceSourceMap==null){
                        relcopoList.get(j).setExcellent(new BigDecimal(0));
                    }else{
                        relcopoList.get(j).setExcellent(new BigDecimal(String.valueOf(exceSourceMap.get("excellent"))));
                    }

                }else{
                    //说明当前学生没有学这个能力的某个课程了，且这个课程属于未开课状态，且能力值为0
                    relcopoList.get(j).setOpenClassState(TeaStatisticsEnum.CLOSE.getCode());
                    relcopoList.get(j).setPowerSource(new BigDecimal(0));
                    if(exceSourceMap==null){
                        relcopoList.get(j).setExcellent(new BigDecimal(0));
                    }else{
                        relcopoList.get(j).setExcellent(new BigDecimal(String.valueOf(exceSourceMap.get("excellent"))));
                    }

                }
            }
        }
        return relcopoListAllOne;
    }

    //将expreLongList这个集合转换为CourseOrExpre对象的集合
    public List<CourseOrExpre> getExpreLongListTwo(List<Map<String,Object>> expreLongList ){
        List<CourseOrExpre> expreLongListTwo = new ArrayList<>();
        for(int i=0;i<expreLongList.size();i++){
            CourseOrExpre ce = new CourseOrExpre();
            ce.setCourseId(Integer.valueOf(String.valueOf(expreLongList.get(i).get("courseId"))));
            expreLongListTwo.add(ce);
        }
        return expreLongListTwo;
    }
    //将每个能力对应的课程放在一起
    public List<Map<String,Object>> getRelCoPoListOne(List<Map<String,Object>> coursePowerList,List<Map<String,Object>> allCoursePowerList){
        List<Map<String,Object>> relcopoListAllOne = new ArrayList<>();
        for(int i=0;i<coursePowerList.size();i++){
            List<CourseOrExpre> relcopoList = new ArrayList<>();
            Map<String,Object> coPoMap = new HashMap<>();
            coPoMap.put("powerId",coursePowerList.get(i).get("powerId"));
            coPoMap.put("powerName",coursePowerList.get(i).get("powerName"));
            for(int j=0;j<allCoursePowerList.size();j++){
                CourseOrExpre ce = new CourseOrExpre();
                if(Integer.valueOf(String.valueOf(coursePowerList.get(i).get("powerId")))==Integer.valueOf(String.valueOf(allCoursePowerList.get(j).get("powerId")))){
                   ce.setCourseId(Integer.valueOf(String.valueOf(allCoursePowerList.get(j).get("courseId"))));
                   ce.setCourseName(String.valueOf(allCoursePowerList.get(j).get("courseName")));
                   ce.setWidth(Float.parseFloat(String.valueOf(allCoursePowerList.get(j).get("width"))));
                   ce.setHomeworkWidth(Float.parseFloat(String.valueOf(allCoursePowerList.get(j).get("homeworkWidth"))));
                   ce.setExamWidth(Float.parseFloat(String.valueOf(allCoursePowerList.get(j).get("examWidth"))));
                   ce.setExpreWidth(Float.parseFloat(String.valueOf(allCoursePowerList.get(j).get("expreWidth"))));
                   relcopoList.add(ce);
                }
            }
            coPoMap.put("relcopoList",relcopoList);
            relcopoListAllOne.add(coPoMap);
        }
        return relcopoListAllOne;
    }

    /**
     *
     * @param a 总数（被除数）
     * @param b 少数（除数）
     * @return
     */
    private BigDecimal calculationRate(BigDecimal a,BigDecimal b){
        BigDecimal rate = new BigDecimal(0);
        if(b!=null&&!(b.equals("null"))&&!(b.compareTo(BigDecimal.ZERO)==0)&&
                (a!=null&&!(a.equals("null"))&&!(a.compareTo(BigDecimal.ZERO)==0))){
            rate = b.divide(a,2,BigDecimal.ROUND_HALF_UP);
        }
        return rate;
    }


    /**
     *
     * @param taskTwoList 学生对应所有作业信息
     * @param knowStuList 学生对应作业信息==对应的知识点集合(有重复的)
     * @param knowpointnoRepeatList 去重后的知识点集合
     * @param knowpointAllNoRepeatList 全部知识点去重后的集合
     * @description 1.查出当前学生所学课程对应作业信息
                    2.查出当前学生所学课程对应作业信息===对应的知识点信息（这里面有重复数据）
                    3.取出1中学生提交作业的【题id、答案】集合
                    4.将3和4进行对比比对出错误与否（这里面包含着重复的知识点）
                    5.将2中知识点重复数据去重后与4的结果进行对比，将相同知识点的放在一起，看是否是全对或全错
     * @return
     */
    private Map<String,Object> RightOrWorng(List<Map<String,Object>> taskTwoList,List<Map<String,Object>> knowStuList,List<Map<String,Object>> knowpointnoRepeatList,List<Map<String,Object>> knowpointAllNoRepeatList){
        Map<String,Object> paramMap = new HashMap<>();
        Map<String,Object> resultMap = new HashMap<>();
        //将学生对应所有作业信息变成map
        Map<String , Map<String, Object>> taskmap = MapUtils.transform(taskTwoList, new Function<Map<String, Object>,String>() {
            @Nullable
            public String apply(@Nullable Map<String, Object> input) {
                String str = String.valueOf(input.get("chapterId"));
                return str;
            }
        });

        //答案正确的集合
        List<TaskLibraryVO> answerTrueList = new ArrayList<>();
        //答案错误的集合
        List<TaskLibraryVO> answerFlaseList = new ArrayList<>();
        //答案正确的集合的赋值
        List<TaskLibraryVO> answerTrueListCopy = new ArrayList<>();
        //将全部知识点与学生提交作业的知识点进行长度对比
        if(knowpointnoRepeatList.size()<knowpointAllNoRepeatList.size()){
            //说明学生有没提交的作业，取全部知识重点与学生提交作业知识点的差集===差集这部分就是学生没提交作业部分的知识点===将其全部置为错误
            knowpointAllNoRepeatList.removeAll(knowpointnoRepeatList);
            for(int i=0;i<knowpointAllNoRepeatList.size();i++){
                TaskLibraryVO taskLibrary = new TaskLibraryVO();
                taskLibrary.setChapterId(Integer.valueOf(String.valueOf(knowpointAllNoRepeatList.get(i).get("chapterId"))));
                taskLibrary.setTasklibrary_knowpoint(String.valueOf(knowpointAllNoRepeatList.get(i).get("tasklibrary_knowpoint")));
                taskLibrary.setCourseId(Integer.valueOf(String.valueOf(knowpointAllNoRepeatList.get(i).get("courseId"))));
                taskLibrary.setGrade(KnowGradeEnum.BAD.getCode());
                answerFlaseList.add(taskLibrary);
            }
        }
        for(int i=0;i<knowStuList.size();i++){
            String chapterId1 = String.valueOf(knowStuList.get(i).get("chapterId"));
            int tasklibrary_id1 = Integer.parseInt(String.valueOf(knowStuList.get(i).get("tasklibrary_id")));
            //取出对应的学生提交作业答案
            Map<String,Object> taskMap = taskmap.get(chapterId1);
            String taskAddress = String.valueOf(taskMap.get("taskAddress"));
            //将字符串变成集合
            List<Map<String,Object>> answerList = (List<Map<String, Object>>) JSONObject.parseArray(taskAddress , paramMap.getClass());
            for(int j=0;j<answerList.size();j++){
                int tasklibrary_id2 = Integer.parseInt(String.valueOf(answerList.get(j).get("questionId")));
                if(tasklibrary_id1 == tasklibrary_id2){
                    boolean manyFlag = false;
                    //判断当前学生的答案是否正确
                    String answer1 = String.valueOf(knowStuList.get(i).get("tasklibrary_answer"));
                    String answer2 = String.valueOf(answerList.get(j).get("ansquesContent"));
                    if(Integer.valueOf(String.valueOf(knowStuList.get(i).get("tasklibrary_type")))==5){
                        //说明是多选会有BD或DB的可能
                        manyFlag = !(PubMethods.isManyOptionTure(answer1.toUpperCase(),answer2.toUpperCase()));
                    }else{
                        manyFlag = answer1.equals(answer2);
                    }
                    if(manyFlag){
                        TaskLibraryVO taskLibrary = new TaskLibraryVO();
                        taskLibrary.setChapterId(Integer.valueOf(chapterId1));
                        taskLibrary.setTasklibrary_knowpoint(String.valueOf(knowStuList.get(i).get("tasklibrary_knowpoint")));
                        taskLibrary.setCourseId(Integer.valueOf(String.valueOf(taskMap.get("courseId"))));
                        taskLibrary.setGrade(KnowGradeEnum.EXCELLENT.getCode());
                        answerTrueList.add(taskLibrary);
                    }else{
                        TaskLibraryVO taskLibrary = new TaskLibraryVO();
                        taskLibrary.setChapterId(Integer.valueOf(chapterId1));
                        taskLibrary.setTasklibrary_knowpoint(String.valueOf(knowStuList.get(i).get("tasklibrary_knowpoint")));
                        taskLibrary.setCourseId(Integer.valueOf(String.valueOf(taskMap.get("courseId"))));
                        taskLibrary.setGrade(KnowGradeEnum.BAD.getCode());
                        answerFlaseList.add(taskLibrary);
                    }
                }
            }
        }

        //将answerTrueList拷贝一份
        for(TaskLibraryVO demo : answerTrueList){
            answerTrueListCopy.add((TaskLibraryVO) demo.clone());
        }
       /* for(TaskLibraryVO demo : answerFlaseList){
            answerFlaseListCopy.add((TaskLibraryVO) demo.clone());
        }*/
        //获取对的集合和错的集合的交集
        answerTrueListCopy.retainAll(answerFlaseList);
        //获取到的交集--相当于是良的集合
        List<TaskLibraryVO> intersectionList = (List<TaskLibraryVO>) answerTrueListCopy;
        //将补集的等级变为良
        for (TaskLibraryVO taskLibraryVO:intersectionList){
            taskLibraryVO.setGrade(2);
        }

        //获取answerTrueList与answerTrueListCopy的差集
        answerTrueList.removeAll(answerTrueListCopy);
        //获取answerFlaseList与answerTrueListCopy的差集
        answerFlaseList.removeAll(answerTrueListCopy);
        //将分好的等级集合合并
        List<TaskLibraryVO> finalList = new ArrayList<>();
        finalList.addAll(answerTrueList);
        finalList.addAll(intersectionList);
        finalList.addAll(answerFlaseList);
        resultMap.put("knowFinalList",finalList);
        return resultMap;

    }


    //获取知识点的个数
    public List<Map<String,Object>> getCount(List<TaskLibraryVO> knowStuList){
        //将List转换为Set
        Set uniqueSetOne = new HashSet(knowStuList);
        //统计总的知识点个数的集合
        List<Map<String,Object>> everyListOne = new ArrayList<>();
        for (Object temp : uniqueSetOne) {
            TaskLibraryVO objectMap = (TaskLibraryVO) temp;
            Map<String,Object> everyMap = new HashMap<>();
            everyMap.put(((TaskLibraryVO) temp).getTasklibrary_knowpoint()+","+((TaskLibraryVO) temp).getCourseId(),Collections.frequency(knowStuList, temp));
            everyListOne.add(everyMap);
        }
        return everyListOne;
    }

    //获取知识点的个数
    public List<Map<String,Object>> getCountMap(List<Map<String,Object>> knowStuList){
        //将List转换为Set
        Set uniqueSetOne = new HashSet(knowStuList);
        //统计总的知识点个数的集合
        List<Map<String,Object>> everyListOne = new ArrayList<>();
        for (Object temp : uniqueSetOne) {
            Map<String,Object> objectMap = (Map<String, Object>) temp;
            Map<String,Object> everyMap = new HashMap<>();
            everyMap.put(String.valueOf(((Map<String, Object>) temp).get("tasklibrary_knowpoint")+","+((Map<String, Object>) temp).get("courseId")),Collections.frequency(knowStuList, temp));
            everyListOne.add(everyMap);
        }
        return everyListOne;
    }

    //去重
    public List<Map<String,Object>> noRepeatList(List<Map<String,Object>> knowpointList){
        List<Map<String,Object>> knowpointListCopy = new ArrayList<>();
        for (int i=0;i<knowpointList.size();i++){
            Map<String,Object> map = new HashMap<>();
            map.put("tasklibrary_knowpoint",knowpointList.get(i).get("tasklibrary_knowpoint"));
            map.put("courseId",knowpointList.get(i).get("courseId"));
            map.put("chapterId",knowpointList.get(i).get("chapterId"));
            map.put("tasklibrary_id",knowpointList.get(i).get("tasklibrary_id"));
            knowpointListCopy.add(map);
        }

        if(knowpointListCopy!=null&&knowpointListCopy.size()!=0){
            for  ( int  i  =   0 ; i  <  knowpointListCopy.size()  -   1 ; i ++ )  {
                for  ( int  j  =  knowpointListCopy.size()  -   1 ; j  >  i; j -- )  {
                    if  (String.valueOf(knowpointListCopy.get(j).get("tasklibrary_knowpoint")).equals(String.valueOf(knowpointListCopy.get(i).get("tasklibrary_knowpoint")))&&
                            String.valueOf(knowpointListCopy.get(j).get("courseId")).equals(String.valueOf(knowpointListCopy.get(i).get("courseId"))))  {
                        knowpointListCopy.remove(j);
                    }
                }
            }
        }
        return knowpointListCopy;
    }

    /**
     * 计算知识点等级及个数
     * @param knowpointAllList 所有知识点集合
     * @param knowpointList 去重后的知识点集合
     * @return
     */
    private Map<String,Object> knowGrade(List<Map<String,Object>> knowpointAllList,List<Map<String,Object>> knowpointList){
        //最后返回的map
        Map<String,Object> finalMap = new HashMap<>();
        //最后合并后的知识点集合
        List<Map<String,Object>> finalKnowList = new ArrayList<>();
        //最后合并后的知识点个数
        Map<String,Object> finalKnowCountMap = new HashMap<>();
        //相同知识点的集合
        List<Map<String,Object>> sameList = new ArrayList<>();
        //每个知识点对应的个数
        List<Map<String,Object>> everyKnowList = new ArrayList<>();
        //将相同知识点的集合放在一起
        for(int i=0;i<knowpointList.size();i++){
            Map<String,Object> everyKnowMap = new HashMap<>();
            //每个知识点的个数
            int count = 0;
            for(int j=0;j<knowpointAllList.size();j++){
                Map<String,Object> sameMap = new HashMap<>();
                if(Integer.parseInt(String.valueOf(knowpointList.get(i).get("courseId")))==Integer.parseInt(String.valueOf(knowpointAllList.get(j).get("courseId")))){
                    //将相同知识点放到一起
                    if(String.valueOf(knowpointList.get(i).get("tasklibrary_knowpoint")).equals(String.valueOf(knowpointAllList.get(j).get("tasklibrary_knowpoint")))){
                        count = count+1;
                        sameMap.put("tasklibrary_knowpoint",knowpointAllList.get(j).get("tasklibrary_knowpoint"));
                        sameMap.put("courseId",knowpointAllList.get(j).get("courseId"));
                        sameMap.put("tasklibrary_answer",knowpointAllList.get(j).get("tasklibrary_answer"));
                        sameList.add(sameMap);
                    }
                }
            }
            everyKnowMap.put("tasklibrary_knowpoint",knowpointList.get(i).get("tasklibrary_knowpoint"));
            everyKnowMap.put("count",count);
            everyKnowMap.put("courseId",knowpointList.get(i).get("courseId"));
            everyKnowList.add(everyKnowMap);
        }
        //判断知识点对错
        int greatCount = 0;
        int commonlyCount = 0;
        int brokenCount = 0;
        for(int i=0;i<everyKnowList.size();i++){
            for(int j=0;j<sameList.size();j++){
                Map<String,Object> excellMap = new HashMap<>();
                Map<String,Object> badMap = new HashMap<>();
                Map<String,Object> soMap = new HashMap<>();
                int mark = 0;
                int excellentCount = 0;
                int badCount = 0;
                if(Integer.parseInt(String.valueOf(everyKnowList.get(i).get("courseId")))==Integer.parseInt(String.valueOf(sameList.get(j).get("courseId")))){
                    if(String.valueOf(everyKnowList.get(i).get("tasklibrary_knowpoint")).equals(String.valueOf(sameList.get(j).get("tasklibrary_knowpoint")))){
                        //判断知识点对错
                        if(String.valueOf(sameList.get(j).get("tasklibrary_knowpoint")).equals(String.valueOf(sameList.get(j).get("tasklibrary_answer")))){
                            mark =  KnowGradeEnum.EXCELLENT.getCode();
                            excellentCount = excellentCount+1;
                        }
                        if(!String.valueOf(sameList.get(j).get("tasklibrary_knowpoint")).equals(String.valueOf(sameList.get(j).get("tasklibrary_answer")))){
                            mark = KnowGradeEnum.BAD.getCode();
                            badCount = badCount+1;
                        }
                        //说明全对
                        if(mark==KnowGradeEnum.EXCELLENT.getCode()&&excellentCount==Integer.parseInt(String.valueOf(everyKnowList.get(i).get("count")))){
                            excellMap.put("tasklibrary_knowpoint",everyKnowList.get(i).get("tasklibrary_knowpoint"));
                            excellMap.put("courseId",everyKnowList.get(i).get("courseId"));
                            excellMap.put("grade", KnowGradeEnum.EXCELLENT.getCode());
                            finalKnowList.add(excellMap);
                            greatCount = greatCount+1;
                        }
                        //说明全错
                        if(mark==KnowGradeEnum.BAD.getCode()&&badCount==Integer.parseInt(String.valueOf(everyKnowList.get(i).get("count")))){
                            badMap.put("tasklibrary_knowpoint",everyKnowList.get(i).get("tasklibrary_knowpoint"));
                            badMap.put("courseId",everyKnowList.get(i).get("courseId"));
                            badMap.put("grade", KnowGradeEnum.BAD.getCode());
                            finalKnowList.add(badMap);
                            commonlyCount = commonlyCount+1;
                        }
                        //说明有对有错
                       /* if((mark==KnowGradeEnum.BAD.getCode()&&badCount!=Integer.parseInt(String.valueOf(everyKnowList.get(i).get("count"))))||
                                (mark==KnowGradeEnum.EXCELLENT.getCode()&&excellentCount!=Integer.parseInt(String.valueOf(everyKnowList.get(i).get("count"))))||
                                mark==0){
                            soMap.put("tasklibrary_knowpoint",everyKnowList.get(i).get("tasklibrary_knowpoint"));
                            soMap.put("courseId",everyKnowList.get(i).get("courseId"));
                            soMap.put("grade", KnowGradeEnum.GRAT.getCode());
                            finalKnowList.add(soMap);
                            brokenCount = brokenCount+1;
                        }*/
                    }
                }
            }
        }
        brokenCount = everyKnowList.size()-commonlyCount-greatCount;
        finalMap.put("finalKnowList",finalKnowList);
        finalKnowCountMap.put("excellentCount",greatCount);
        finalKnowCountMap.put("brokenCount",brokenCount);
        finalKnowCountMap.put("commonlyCount",commonlyCount);
        finalMap.put("finalKnowCountMap",finalKnowCountMap);
        //将优和差的剔除，取finalKonwList和everyKnowList的补急
        Collection complementList = new ArrayList<Map<String,Object>>(everyKnowList);
        finalKnowList.removeAll(complementList);
        List<Map<String,Object>> complementList1 = finalKnowList;
        finalKnowList.add(complementList1.get(0));

        return finalMap;
    }

    /**
     * 保存学生报告html
     * param:学生id,reportHtml
     * @return
     * @throws IOException
     */
    public Map<String, Object> saveReportHtmlByStuId(Map<String,Object> parameMap,HttpServletRequest request) throws Exception {

        Map<String, Object> returnMap = new HashMap<String, Object>();
        boolean flag = false;
        try {
            //获取当前登陆人的工号
            String stuorteaId = PubMethods.loginId(request);
            parameMap.put("teaId",stuorteaId);
            //通过学号查询学生姓名
            List<Map<String, Object>> memList = memberDao.getMemberByStuorteaId(String.valueOf(parameMap.get("stuorteaId")));
            String reportBeFileName = "";
            String reportFileName = "";
            String fileName = "";
            List<Map<String,Object>> reportList = new ArrayList<>();
            if(Integer.parseInt(String.valueOf(parameMap.get("mark")))==1){
                //是学生的学习报告
                reportBeFileName = String.valueOf(memList.get(0).get("userName"))+String.valueOf(parameMap.get("stuorteaId"))+ "原学习报告.pdf";
                reportFileName = String.valueOf(memList.get(0).get("userName"))+String.valueOf(parameMap.get("stuorteaId"))+ "学习报告.pdf";
                fileName = String.valueOf(memList.get(0).get("userName"))+String.valueOf(parameMap.get("stuorteaId"))+ "学习报告.html";
                //查询当前学生对应的学习报告是否已经存在
                reportList  = teaStatisticsDao.getReportBysIdAndTeaId(parameMap);
            }else{
                //是教师的统计报告
                reportBeFileName = stuorteaId+ "原统计报告报告.pdf";
                reportFileName =stuorteaId+ "统计报告.pdf";
                fileName = stuorteaId+ "统计报告.html";
                //查询当前教师对应的统计报告是否已经存在
                reportList  = teaStatisticsDao.getTeaReportByTeaId(parameMap);
            }

            parameMap.put("reportFileName",fileName);
            returnMap.put("reportFileName",fileName);

            if(reportList!=null&&reportList.size()!=0){
                flag = teaStatisticsDao.updateReportHtmlByStuId(parameMap);
            }else{
                flag = teaStatisticsDao.saveReportHtmlByStuId(parameMap);
            }
            //文件地址前缀
            String[] keysArray = {"tomcatUrl", "project_name","server_address"};
            Map<String, Object> urlmap = ConfigFileUtil.getFileMessage("UtilFile.properties", keysArray);
            //判断文件夹存不存在,不存在就创建
            String path = String.valueOf(urlmap.get("tomcatUrl"))+String.valueOf(urlmap.get("project_name"))+"upload/report/";
            String returnUrl = String.valueOf(urlmap.get("server_address"))+String.valueOf(urlmap.get("project_name"))+"upload/report/";
            String filpathHtml = "";
            if(Integer.parseInt(String.valueOf(parameMap.get("mark")))==1){
                filpathHtml = path+String.valueOf(memList.get(0).get("userName"))+String.valueOf(parameMap.get("stuorteaId"))+"学习报告.html";
            }if(Integer.parseInt(String.valueOf(parameMap.get("mark")))==2){
                filpathHtml = path+stuorteaId+"统计报告.html";
            }
            String filBepathPdf = path+reportBeFileName;
            String filNewpathPdf = path+reportFileName;

            /*String path = "C://Users/Administrator/Desktop/xxbg/upload/report/";
            String filpathHtml = path+String.valueOf(memList.get(0).get("userName"))+String.valueOf(parameMap.get("stuorteaId"))+"学习报告.html";
            String filBepathPdf = path+reportBeFileName;
            String filNewpathPdf = path+reportFileName;*/

            File saveFile = new File(path);
            if (!saveFile.exists()) {
                String s = path.substring(0,path.lastIndexOf("/") + 1);
                File saveFileDir = new File(s);
                saveFileDir.mkdirs();
                saveFile = new File(path);
            }
            //将html代码转换成pdf
            coverHtml(String.valueOf(parameMap.get("reportHtml")),String.valueOf(parameMap.get("cssStr")),filpathHtml,filBepathPdf,filNewpathPdf,request);

            returnMap.put("flag",flag);
            returnMap.put("path",returnUrl);
        } catch (Exception e) {
            throw e;
        }
        return returnMap;
    }

    private void coverHtml(String str,String cssStr,String filpathHtml,String filpathPdf,String filNewpathPdf,HttpServletRequest request){

        String head = "<!DOCTYPE html>" +
                "<html>" +
                "<head>" +
                "<meta charset=\"UTF-8\" />" +
                "<title></title>" +
                "</head>" +
                "<style>";
        String headTwo = "</style>"+
                "<body id=\"contentBox\">";

        String foot = "</body></html>";
        String newStr = head+cssStr+headTwo+str+foot;
        try {
            StringBuilder sb = new StringBuilder(newStr);
            PrintStream printStream = null ;
            printStream= new PrintStream(new FileOutputStream(filpathHtml));//路径默认在项目根目录下
            printStream.println(sb.toString());
            File f = new File(filpathHtml);
            printStream.close();
            if(f.exists()){
                //转pdf
                htmlToPdf(filpathHtml,filpathPdf);
                //加图片
//                addImage(filpathPdf,filNewpathPdf,request);
                //将没用的两个文件删除（html和原pdf）
               /* FileUpload fileUpload = new FileUpload();
                fileUpload.deleteFileOnly(filpathHtml);
                fileUpload.deleteFileOnly(filpathPdf);*/
            }

        }catch (Exception e){
            e.printStackTrace();
        }


    }

    //加图片
    private void addImage(String filBepathPdf,String fileNewpathPdf,HttpServletRequest request) throws IOException, DocumentException {
        PdfReader reader = new PdfReader(filBepathPdf);
        PdfStamper stamp = new PdfStamper(reader,new FileOutputStream(fileNewpathPdf));
        String imagePath = request.getSession().getServletContext().getRealPath("pc/images/logo2.png");
        Image img = Image.getInstance(imagePath);  //使用png格式
        Document document = new Document(PageSize.A4);
        img.setAlignment(Image.LEFT | Image.TEXTWRAP);
        img.setBorderWidth(10);
        img.setAbsolutePosition(420,document.bottom());
        img.scaleToFit(1000, 60);// 大小
        PdfContentByte over = stamp.getUnderContent(reader.getNumberOfPages()); // overCount 与underCount
        over.addImage(img);
        stamp.close();
        reader.close();
    }
    private void htmlToPdf(String htmlPath,String pdfPath){
        try {
            Document document = new Document(PageSize.A4);
            PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(pdfPath));
            document.open();
            document.addAuthor("test");
            document.addCreator("test");
            document.addSubject("test");
            document.addCreationDate();
            document.addTitle("XHTML to PDF");
            XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
            worker.parseXHtml(pdfWriter, document, new FileInputStream(htmlPath), (InputStream) null, new AsianFontProvider());
            document.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 计算平均时长or平均成绩
     * @param sumList
     * @param countList
     * @param avgMap
     * @param type  1计算平均时长   2平均成绩
     * @return:返回的大集合中是：总成绩or总时长、平时成绩总成绩、考试成绩总成绩、平均时长or平均总成绩、平均平时成绩、平均考试成绩、课程id、课程名称
     */
    public  List<Map<String,Object>> pubAvgList(List<Map<String,Object>> sumList,List<Map<String,Object>> countList,Map<String,Object> avgMap,int type,int applicationType){
        List<Map<String,Object>> list = new ArrayList<Map<String, Object>>();
        //实验学习平均实长or平均成绩
        BigDecimal avgLong = new BigDecimal(0);
        BigDecimal avgSource = new BigDecimal(0);
        BigDecimal avgPerexam = new BigDecimal(0);
        BigDecimal avgExam = new BigDecimal(0);
        BigDecimal sumsource = new BigDecimal(0);
        BigDecimal sumLong = new BigDecimal(0);
        BigDecimal sumperexam = new BigDecimal(0);
        BigDecimal sumexam = new BigDecimal(0);
        //及格率
        BigDecimal passRate = new BigDecimal(0);
        //实验报告提交率
        BigDecimal expreRate = new BigDecimal(0);
        //作业提交率
        BigDecimal taskRate = new BigDecimal(0);
        //标识是课程详情还是课程
        boolean flag=false;
        for(int i=0;i<sumList.size();i++){
            for(int j=0;j<countList.size();j++){
                if(applicationType==1){
                    if(String.valueOf(sumList.get(i).get("courseId")).equals(String.valueOf(countList.get(j).get("courseId")))){
                        flag=true;
                    }
                }if(applicationType==2){
                    if(String.valueOf(sumList.get(i).get("classId")).equals(String.valueOf(countList.get(j).get("classId")))){
                        flag=true;
                    }
                }
                if(flag){
                    Map<String,Object> expreMap = new HashMap<String, Object>();
                    if(Integer.parseInt(String.valueOf(countList.get(j).get("stucount")))==0){
                        //说明学生数量为0（分母为0）平均时长则直接给0
                        avgLong = new BigDecimal(0);
                        avgSource = new BigDecimal(0);
                        avgPerexam = new BigDecimal(0);
                        avgExam = new BigDecimal(0);
                    }else{
                        BigDecimal stucount = new BigDecimal(Integer.parseInt(String.valueOf(countList.get(j).get("stucount"))));
                        if(type==1){
                            sumLong = new BigDecimal(String.valueOf(sumList.get(i).get(String.valueOf(avgMap.get("sumLong")))));
                            avgLong = sumLong.divide(stucount,2,BigDecimal.ROUND_HALF_UP);
                        } if(type==2){
                            sumsource = new BigDecimal(String.valueOf(sumList.get(i).get(String.valueOf(avgMap.get("sumsource")))));
                            avgSource = sumsource.divide(stucount,2,BigDecimal.ROUND_HALF_UP);
                            //平均平时成绩、平均考试成绩
                            sumperexam = new BigDecimal(String.valueOf(sumList.get(i).get(String.valueOf(avgMap.get("sumperexam")))));
                            sumexam = new BigDecimal(String.valueOf(sumList.get(i).get(String.valueOf(avgMap.get("sumexam")))));
                            avgPerexam = sumperexam.divide(stucount,2,BigDecimal.ROUND_HALF_UP);
                            avgExam = sumexam.divide(stucount,2,BigDecimal.ROUND_HALF_UP);
                        }
                    }
                    if(applicationType==2){
                        expreMap.put("className",sumList.get(i).get("className"));
                        expreMap.put("classId",sumList.get(i).get("classId"));

                    }
                    expreMap.put("avgPerexam",avgPerexam);
                    expreMap.put("avgExam",avgExam);
                    expreMap.put("avgLong",avgLong);
                    expreMap.put("avgSource",avgSource);
                    expreMap.put("courseId",sumList.get(i).get("courseId"));
                    expreMap.put("courseName",countList.get(j).get("courseName"));
                    expreMap.put("sumLong",sumLong);
                    expreMap.put("sumsource",sumsource);
                    expreMap.put("sumperexam",sumperexam);
                    expreMap.put("sumexam",sumexam);
                    list.add(expreMap);
                    break;
                }
            }
            flag=false;
        }
        return list;
    }

    /**
     * 计算及格率or实验提价率or作业提交率
     * @param application1  1算及格率or实验提价率or作业提交率  2
     * @param homeOrExpreMark  1实验提价率or作业提交率
     * @param avgMap
     * @param type
     * @return:返回的大集合中是：总成绩or总时长、平时成绩总成绩、考试成绩总成绩、平均时长or平均总成绩、平均平时成绩、平均考试成绩、课程id、课程名称
     */
    public  List<Map<String,Object>> rateList(List<Map<String,Object>> sumList,List<Map<String,Object>> teachList,int application,int homeOrExpreMark){
        List<Map<String,Object>> list = new ArrayList<Map<String, Object>>();
        //及格率or实验报告提交率or作业提交率
        BigDecimal rate = new BigDecimal(0);
        boolean flag = false;
        for(int i=0;i<sumList.size();i++){
            for(int j=0;j<teachList.size();j++){
                Map<String,Object> map = new HashMap<String, Object>();
                if(application==1){
                    if(String.valueOf(sumList.get(i).get("courseId")).equals(String.valueOf(teachList.get(j).get("courseId")))){
                        flag = true;
                    }
                } if(application==2){
                    if(String.valueOf(sumList.get(i).get("classId")).equals(String.valueOf(teachList.get(j).get("classId")))){
                        flag = true;
                    }
                }
                if(flag){
                    if(String.valueOf(teachList.get(j).get("teachStuNum")).equals("0")||String.valueOf(sumList.get(i).get("sumcount")).equals("0")){
                        rate = new BigDecimal(0);
                    }else{
                        BigDecimal count = new BigDecimal(Double.parseDouble(String.valueOf(sumList.get(i).get("sumcount"))));
                        if(homeOrExpreMark==1){
                            //人数*章节数
                            int totalFinal = Integer.parseInt(teachList.get(j).get("teachStuNum").toString()) * Integer.parseInt(teachList.get(j).get("chapterSum").toString());
                            rate = count.divide(new BigDecimal(String.valueOf(totalFinal)),2,BigDecimal.ROUND_HALF_UP);
                        }else{
                            rate = count.divide(new BigDecimal(String.valueOf(teachList.get(j).get("teachStuNum"))),2,BigDecimal.ROUND_HALF_UP);
                        }

                    }
                    map.put("courseId",sumList.get(i).get("courseId"));
                    map.put("classId",sumList.get(i).get("classId"));
                    map.put("rate",rate);
                    list.add(map);
                    break;
                }
            }
            flag = false;
        }
        return list;
    }
    /**
     * 将（正在学习人数or已学人数（未结课的or已结课的）、问题交流问题数、回答问题数）与（实验总时长or实验学习平均实长）集合合并
     * @param list1
     * @param list2
     * @return
     */
    public List<Map<String,Object>> mergeList(List<Map<String,Object>> list1,List<Map<String,Object>> list2,int application){
        List <Map<String,Object>> list = new ArrayList<Map<String, Object>>();
        boolean flag = false;
        for(int i=0;i<list1.size();i++){
            for(int j=0;j<list2.size();j++){
                Map<String,Object> map = new HashMap<String, Object>();
                if(application==1){
                    if(String.valueOf(list1.get(i).get("courseId")).equals(String.valueOf(list2.get(j).get("courseId")))){
                        flag = true;
                    }
                } if(application==2){
                    if(String.valueOf(list1.get(i).get("classId")).equals(String.valueOf(list2.get(j).get("classId")))){
                        flag = true;
                    }
                }
                if(flag){
                    map.put("courseId",list1.get(i).get("courseId"));
                    map.put("saveMark",list1.get(i).get("saveMark"));
                    map.put("courseWordPack",list1.get(i).get("courseWordPack"));
                    map.put("classId",list1.get(i).get("classId"));
                    map.put("classEndMark",list1.get(i).get("classEndMark"));
                    map.put("stucount",list1.get(i).get("stucount"));
                    map.put("courseName",list1.get(i).get("courseName"));
                    map.put("courseTitle",list1.get(i).get("courseTitle"));
                    map.put("problemcount",list1.get(i).get("problemcount"));
                    map.put("answercount",list1.get(i).get("answercount"));
                    map.put("avgPerexam",list2.get(j).get("avgPerexam"));
                    map.put("className",list2.get(j).get("className"));
                    map.put("classId",list2.get(j).get("classId"));
                    map.put("avgExam",list2.get(j).get("avgExam"));
                    map.put("avgLong",list2.get(j).get("avgLong"));
                    map.put("avgSource",list2.get(j).get("avgSource"));
                    map.put("sumLong",list2.get(j).get("sumLong"));
                    map.put("sumsource",list2.get(j).get("sumsource"));
                    map.put("sumperexam",list2.get(j).get("sumperexam"));
                    map.put("sumexam",list2.get(j).get("sumexam"));
                    list.add(map);
                    break;
                }
            }
            flag = false;
        }
        return list;
    }

    /**
     *
     * @param list1 及格率
     * @param list2 实验提交率
     * @param list3  作业提交率
     * @return
     */
    public List<Map<String,Object>> rateAllListOne(List<Map<String,Object>> list1,List<Map<String,Object>> list2,List<Map<String,Object>> list3,int applicationType){
        List<Map<String,Object>> listOne = new ArrayList<Map<String, Object>>();
        List<Map<String,Object>> listTwo = new ArrayList<Map<String, Object>>();
        boolean flag = false;
        if(list1!=null&&list1.size()!=0){
            for(int i=0;i<list1.size();i++){
                if(list2!=null&&list2.size()!=0){
                    for (int j=0;j<list2.size();j++){
                        Map<String,Object> map = new HashMap<String, Object>();
                        if(applicationType==1){
                            if(String.valueOf(list1.get(i).get("courseId")).equals(String.valueOf(list1.get(j).get("courseId")))){
                                flag = true;
                            }
                        }if(applicationType==2){
                            if(String.valueOf(list1.get(i).get("classId")).equals(String.valueOf(list1.get(j).get("classId")))){
                                flag = true;
                            }
                        }
                        if(flag){
                            map.put("courseId",list1.get(i).get("courseId"));
                            map.put("classId",list1.get(i).get("classId"));
                            map.put("passRate",list1.get(i).get("rate"));
                            map.put("expreRate",list2.get(j).get("rate"));
                            map.put("taskRate",0);
                            listOne.add(map);
                            break;
                        }
                    }
                }else{
                    Map<String,Object> map = new HashMap<String, Object>();
                    map.put("courseId",list1.get(i).get("courseId"));
                    map.put("classId",list1.get(i).get("classId"));
                    map.put("passRate",list1.get(i).get("rate"));
                    map.put("expreRate",0);
                    map.put("taskRate",0);
                    listOne.add(map);
                }
                flag = false;
            }
        }


        for(int k=0;k<listOne.size();k++){
            if(list3!=null&&list3.size()!=0){
                for(int h=0;h<list3.size();h++){
                    Map<String,Object> map = new HashMap<String, Object>();
                    if(applicationType==1){
                        if(String.valueOf(listOne.get(k).get("courseId")).equals(String.valueOf(list3.get(h).get("courseId")))){
                            flag = true;
                        }
                    }if(applicationType==2){
                        if(String.valueOf(listOne.get(k).get("classId")).equals(String.valueOf(list3.get(h).get("classId")))){
                            flag = true;
                        }
                    }
                    if(flag){
                        map.put("courseId",listOne.get(k).get("courseId"));
                        map.put("classId",listOne.get(k).get("classId"));
                        map.put("passRate",listOne.get(k).get("passRate"));
                        map.put("expreRate",listOne.get(k).get("expreRate"));
                        map.put("taskRate",list3.get(h).get("rate"));
                        listTwo.add(map);
                        break;
                    }
                }
            }else{
                Map<String,Object> map = new HashMap<String, Object>();
                map.put("courseId",listOne.get(k).get("courseId"));
                map.put("classId",listOne.get(k).get("classId"));
                map.put("passRate",listOne.get(k).get("passRate"));
                map.put("expreRate",listOne.get(k).get("expreRate"));
                map.put("taskRate",0);
                listTwo.add(map);
                break;
            }
            flag = false;
        }
        return listTwo;
    }

    /**
     *将AvgExperimentTimeMargeList集合与rateList集合合并
     * @param list1：AvgExperimentTimeMargeList
     * @param list2：rateList  比率部分
     * @param list3：AvgExamList 成绩部分
     * @return
     */
    public List<Map<String,Object>> listAllOne(List<Map<String,Object>> list1,List<Map<String,Object>> list2,List<Map<String,Object>> list3,int applicationType){
        //先将AvgExperimentTimeMargeList集合与rateList集合合并
        List<Map<String,Object>> listOne = new ArrayList<Map<String, Object>>();
        List<Map<String,Object>> listTwo = new ArrayList<Map<String, Object>>();
        boolean flag = false;
        int mark=0;
        for(int i=0;i<list1.size();i++){
            if(list2!=null&&list2.size()!=0){
                for(int j=0;j<list2.size();j++){
                    Map<String,Object> map = new HashMap<String, Object>();
                    if(applicationType==1){
                        if(String.valueOf(list1.get(i).get("courseId")).equals(String.valueOf(list2.get(j).get("courseId")))){
                            flag = true;
                        }if(!String.valueOf(list1.get(i).get("courseId")).equals(String.valueOf(list2.get(j).get("courseId")))
                                &&(list1.get(i).get("courseId")==null||list2.get(j).get("courseId")==null)){
                            flag = true;
                            mark=1;
                        }
                    }if(applicationType==2){
                        if(String.valueOf(list1.get(i).get("classId")).equals(String.valueOf(list2.get(j).get("classId")))){
                            flag = true;
                        } if(!String.valueOf(list1.get(i).get("classId")).equals(String.valueOf(list2.get(j).get("classId")))
                                &&(list1.get(i).get("classId")==null||list2.get(j).get("classId")==null)){
                            flag = true;
                            mark=1;
                        }
                    }
                    if(flag){
                        map.put("courseId",list1.get(i).get("courseId"));
                        map.put("courseWordPack",list1.get(i).get("courseWordPack"));
                        map.put("saveMark",list1.get(i).get("saveMark"));
                        map.put("classEndMark",list1.get(i).get("classEndMark"));
                        map.put("stucount",list1.get(i).get("stucount"));
                        map.put("courseName",list1.get(i).get("courseName"));
                        map.put("className",list1.get(i).get("className"));
                        map.put("classId",list1.get(i).get("classId"));
                        map.put("courseTitle",list1.get(i).get("courseTitle"));
                        map.put("problemcount",list1.get(i).get("problemcount"));
                        map.put("answercount",list1.get(i).get("answercount"));
                        map.put("avgPerexam",list1.get(i).get("avgPerexam"));
                        map.put("avgLong",list1.get(i).get("avgLong"));
                        map.put("avgSource",list1.get(i).get("avgSource"));
                        map.put("sumLong",list1.get(i).get("sumLong"));
                        map.put("sumsource",list1.get(i).get("sumsource"));
                        map.put("sumperexam",list1.get(i).get("sumperexam"));
                        map.put("sumexam",list1.get(i).get("sumexam"));
                        if(mark==1){
                            map.put("passRate",0);
                            map.put("expreRate",0);
                            map.put("taskRate",0);
                        }else{
                            map.put("passRate",list2.get(j).get("passRate"));
                            map.put("expreRate",list2.get(j).get("expreRate"));
                            map.put("taskRate",list2.get(j).get("taskRate"));
                        }

                        listOne.add(map);
                        break;
                    }
                }
            }else{
                Map<String,Object> map = new HashMap<String, Object>();
                map.put("courseId",list1.get(i).get("courseId"));
                map.put("courseWordPack",list1.get(i).get("courseWordPack"));
                map.put("saveMark",list1.get(i).get("saveMark"));
                map.put("classEndMark",list1.get(i).get("classEndMark"));
                map.put("stucount",list1.get(i).get("stucount"));
                map.put("courseName",list1.get(i).get("courseName"));
                map.put("className",list1.get(i).get("className"));
                map.put("classId",list1.get(i).get("classId"));
                map.put("courseTitle",list1.get(i).get("courseTitle"));
                map.put("problemcount",list1.get(i).get("problemcount"));
                map.put("answercount",list1.get(i).get("answercount"));
                map.put("avgPerexam",list1.get(i).get("avgPerexam"));
                map.put("avgLong",list1.get(i).get("avgLong"));
                map.put("avgSource",list1.get(i).get("avgSource"));
                map.put("sumLong",list1.get(i).get("sumLong"));
                map.put("sumsource",list1.get(i).get("sumsource"));
                map.put("sumperexam",list1.get(i).get("sumperexam"));
                map.put("sumexam",list1.get(i).get("sumexam"));

                map.put("passRate",0);
                map.put("expreRate",0);
                map.put("taskRate",0);
                listOne.add(map);
            }

            flag = false;
        }

        mark=0;
        //在将成绩部分与listOne合并
        for(int i=0;i<listOne.size();i++){
            if(list3!=null&&list3.size()!=0){
                for(int j=0;j<list3.size();j++){
                    Map<String,Object> map = new HashMap<String, Object>();
                    if(applicationType==1){
                        if(String.valueOf(listOne.get(i).get("courseId")).equals(String.valueOf(list3.get(j).get("courseId")))){
                            flag = true;
                        } if(!String.valueOf(listOne.get(i).get("courseId")).equals(String.valueOf(list3.get(j).get("courseId")))
                                &&(listOne.get(i).get("courseId")==null||list3.get(j).get("courseId")==null)){
                            flag = true;
                            mark=1;
                        }
                    }if(applicationType==2){
                        if(String.valueOf(listOne.get(i).get("classId")).equals(String.valueOf(list3.get(j).get("classId")))){
                            flag = true;
                        }if(!String.valueOf(listOne.get(i).get("classId")).equals(String.valueOf(list3.get(j).get("classId")))
                                &&(listOne.get(i).get("classId")==null||list3.get(j).get("classId")==null)){
                            flag = true;
                            mark=1;
                        }
                    }
                    if(flag){
                        map.put("courseId",listOne.get(i).get("courseId"));
                        map.put("courseWordPack",listOne.get(i).get("courseWordPack"));
                        map.put("saveMark",listOne.get(i).get("saveMark"));
                        map.put("classEndMark",listOne.get(i).get("classEndMark"));
                        map.put("stucount",listOne.get(i).get("stucount"));
                        map.put("courseName",listOne.get(i).get("courseName"));
                        map.put("courseTitle",listOne.get(i).get("courseTitle"));
                        map.put("classId",listOne.get(i).get("classId"));
                        map.put("className",listOne.get(i).get("className"));
                        map.put("problemcount",listOne.get(i).get("problemcount"));
                        map.put("answercount",listOne.get(i).get("answercount"));
                        map.put("avgPerexam",list3.get(j).get("avgPerexam"));
                        map.put("avgLong",listOne.get(i).get("avgLong"));
                        map.put("avgSource",list3.get(j).get("avgSource"));
                        map.put("sumLong",listOne.get(i).get("sumLong"));
                        map.put("sumsource",list3.get(j).get("sumsource"));
                        map.put("avgExam",list3.get(j).get("avgExam"));
                        map.put("sumperexam",list3.get(j).get("sumperexam"));
                        map.put("sumexam",list3.get(j).get("sumexam"));
                        map.put("passRate",listOne.get(i).get("passRate"));
                        map.put("expreRate",listOne.get(i).get("expreRate"));
                        map.put("taskRate",listOne.get(i).get("taskRate"));
                        listTwo.add(map);
                        break;
                    }
                }
            }else{
                Map<String,Object> map = new HashMap<String, Object>();
                map.put("courseId",listOne.get(i).get("courseId"));
                map.put("courseWordPack",listOne.get(i).get("courseWordPack"));
                map.put("saveMark",listOne.get(i).get("saveMark"));
                map.put("classEndMark",listOne.get(i).get("classEndMark"));
                map.put("stucount",listOne.get(i).get("stucount"));
                map.put("courseName",listOne.get(i).get("courseName"));
                map.put("courseTitle",listOne.get(i).get("courseTitle"));
                map.put("classId",listOne.get(i).get("classId"));
                map.put("className",listOne.get(i).get("className"));
                map.put("problemcount",listOne.get(i).get("problemcount"));
                map.put("answercount",listOne.get(i).get("answercount"));
                map.put("avgPerexam",0);
                map.put("avgLong",listOne.get(i).get("avgLong"));
                map.put("avgSource",0);
                map.put("sumLong",listOne.get(i).get("sumLong"));
                map.put("sumsource",0);
                map.put("avgExam",0);
                map.put("sumperexam",0);
                map.put("sumexam",0);
                map.put("passRate",listOne.get(i).get("passRate"));
                map.put("expreRate",listOne.get(i).get("expreRate"));
                map.put("taskRate",listOne.get(i).get("taskRate"));
                listTwo.add(map);

            }

            flag = false;
        }
        return listTwo;
    }

    /**
     * 将集合变成map
     */
    public Map<String, Map<String, Object>> returnMap(List<Map<String,Object>> paramList){
        Map<String , Map<String, Object>> map = MapUtils.transform(paramList, new Function<Map<String, Object>,String>() {
            @Nullable
            public String apply(@Nullable Map<String, Object> input) {
               /* Joiner j = Joiner.on("_");
                j.join(String.valueOf(input.get("stuorteaId")),String.valueOf(input.get("courseId")));*/
                String str = String.valueOf(input.get("stuorteaId")+"_"+String.valueOf(input.get("courseId")));
                return str;
            }
        });
        return map;
    }

    /**
     * 学生详情--将集合变成map
     */
    public Map<String, Map<String, Object>> returnStuMap(List<Map<String,Object>> paramList){
        Map<String , Map<String, Object>> map = MapUtils.transform(paramList, new Function<Map<String, Object>,String>() {
            @Nullable
            public String apply(@Nullable Map<String, Object> input) {
                String str = String.valueOf(input.get("chapterNum"));
                return str;
            }
        });
        return map;
    }

    /**
     * 学生统计--将结果拼接在一起
     */
    public List<Map<String,Object>> getFinalList(List<Map<String,Object>> stuAndCouList, Map<String,Map<String,Object>> expreLongMap, Map<String,Map<String,Object>> proAndAnswerMap,
                                                 Map<String,Map<String,Object>> taskMap, Map<String,Map<String,Object>> expreMap,
                                                 Map<String,Map<String,Object>> expreNotMap, Map<String,Map<String,Object>> sourceMap){
        List<Map<String,Object>> list = new ArrayList<Map<String, Object>>();
        for (int i=0;i<stuAndCouList.size();i++){
            Map<String,Object> finalMap = new HashMap<String, Object>();
            //  取出map里需要的key
            String mapKey = String.valueOf(stuAndCouList.get(i).get("stuorteaId"))+"_"+String.valueOf(stuAndCouList.get(i).get("courseId"));
            Map<String,Object> map1= expreLongMap.get(mapKey);
            Map<String,Object> map2= proAndAnswerMap.get(mapKey);
            Map<String,Object> map3= taskMap.get(mapKey);
            Map<String,Object> map4= expreMap.get(mapKey);
            Map<String,Object> map5= expreNotMap.get(mapKey);
            Map<String,Object> map6= sourceMap.get(mapKey);
            finalMap.put("stuorteaId",map1.get("stuorteaId"));
            finalMap.put("courseId",map1.get("courseId"));
            finalMap.put("sumtime",map1.get("sumtime"));
            finalMap.put("answercount",map2.get("answercount"));
            finalMap.put("problemcount",map2.get("problemcount"));
            finalMap.put("taskcount",map3.get("taskorexprecount"));
            finalMap.put("exprecount",map4.get("taskorexprecount"));
            finalMap.put("exprenotecount",map5.get("exprenotecount"));
            finalMap.put("userName",map6.get("userName"));
            finalMap.put("courseName",map6.get("courseName"));
            finalMap.put("preforSource",map6.get("preforSource"));
            finalMap.put("examSource",map6.get("examSource"));
            finalMap.put("sumSource",map6.get("sumSource"));
            finalMap.put("classId",map6.get("classId"));
            finalMap.put("className",map6.get("className"));
            list.add(finalMap);
        }
        return list;
    }

    /**
     * 学生报告--将结果拼接在一起
     */
    public List<Map<String,Object>> getStuReportFinalList(List<Map<String,Object>> sexpreLongList, Map<String,Map<String,Object>> proAndAnswerMap,
                                                          Map<String,Map<String,Object>> taskMap, Map<String,Map<String,Object>> expreMap,
                                                          Map<String,Map<String,Object>> expreNotMap, Map<String,Map<String,Object>> sourceMap,
                                                          List<TaskLibraryVO> knowpointList,Map<String,Map<String,Object>> homeChapterMap,
                                                          Map<String,Map<String,Object>> testChapterMap,
                                                          Map<String,Map<String,Object>> readorcomMap,Map<String,Map<String,Object>> comCourseMap,
                                                          Map<String,Map<String,Object>> onlineExamMap
                                                          ){
        List<Map<String,Object>> list = new ArrayList<Map<String, Object>>();
        for (int i=0;i<sexpreLongList.size();i++){
            Map<String,Object> finalMap = new HashMap<String, Object>();
            List<Map<String,Object>> knowlist = new ArrayList<Map<String,Object>>();
            int excellentCount = 0;
            int greatCount = 0;
            int badCount = 0;
            //取出每个课程拥有的知识点集合
            for (int j=0;j<knowpointList.size();j++){
                Map<String,Object> paramMap = new HashMap<String, Object>();
                if(String.valueOf(sexpreLongList.get(i).get("courseId")).equals(String.valueOf(knowpointList.get(j).getCourseId()))){
                    if(knowpointList.get(j).getTasklibrary_knowpoint()!=null&&
                            !knowpointList.get(j).getTasklibrary_knowpoint().equals("")&&
                            !knowpointList.get(j).getTasklibrary_knowpoint().equals("null") ){
                        paramMap.put("tasklibrary_knowpoint",knowpointList.get(j).getTasklibrary_knowpoint());
                        paramMap.put("grade",knowpointList.get(j).getGrade());
                        knowlist.add(paramMap);
                    }
                    //计算每个课程各个等级的个数
                    int grade = knowpointList.get(j).getGrade();
                    if(grade==KnowGradeEnum.EXCELLENT.getCode()){
                        excellentCount = excellentCount+1;
                    }if(grade==KnowGradeEnum.GRAT.getCode()){
                        greatCount = greatCount+1;
                    }if(grade==KnowGradeEnum.BAD.getCode()){
                        badCount = badCount+1;
                    }
                    //暂时将实验中的知识点去掉
                    /*if(String.valueOf(knowpointList.get(j).get("exprelibrary_knowpoint"))!=null&&
                            !String.valueOf(knowpointList.get(j).get("exprelibrary_knowpoint")).equals("")&&
                            !String.valueOf(knowpointList.get(j).get("exprelibrary_knowpoint")).equals("null")){
                        knowlist.add(String.valueOf(knowpointList.get(j).get("exprelibrary_knowpoint")));
                    }*/
                }
            }
            //将knowList去重
            knowlist = PubMethods.noRepeatList(knowlist);
            finalMap.put("knowList",knowlist);
            //  取出map里需要的key
            String mapKey = String.valueOf(sexpreLongList.get(i).get("stuorteaId"))+"_"+String.valueOf(sexpreLongList.get(i).get("courseId"));
            Map<String,Object> map2= proAndAnswerMap.get(mapKey);
            Map<String,Object> map3= taskMap.get(mapKey);
            Map<String,Object> map4= expreMap.get(mapKey);
            Map<String,Object> map5= expreNotMap.get(mapKey);
            Map<String,Object> map6= sourceMap.get(mapKey);
            Map<String,Object> map7= homeChapterMap.get(mapKey);
            Map<String,Object> map8= readorcomMap.get(mapKey);
            Map<String,Object> map9= comCourseMap.get(mapKey);
            Map<String,Object> map10= onlineExamMap.get(mapKey);
            Map<String,Object> map11= testChapterMap.get(mapKey);
            //作业提交率（当前学生提交的作业数/当前课程总的作业章节数）
            BigDecimal taskRate = calculationRate(new BigDecimal(String.valueOf(map7.get("chapterCount"))),new BigDecimal(String.valueOf(map3.get("taskorexprecount"))));
           //实验报告提交率（当前学生提交的实验报告数/当前课程总的实验章节数）
            BigDecimal exprementRate = calculationRate(new BigDecimal(String.valueOf(map11.get("chapterCount"))),new BigDecimal(String.valueOf(map4.get("taskorexprecount"))));
            if(map10==null){
                finalMap.put("onlineExamCount",0);
            }if(map10!=null){
                finalMap.put("onlineExamCount",map10.get("onlineExamCount"));
            }
            finalMap.put("taskRate",taskRate);
            finalMap.put("exprementRate",exprementRate);
            finalMap.put("excellentCount",excellentCount);
            finalMap.put("readCourseCount",map8.get("readCourseCount"));
            finalMap.put("comExpreCount",map8.get("comExpreCount"));
            finalMap.put("comCourseCount",map9.get("comCourseCount"));
            finalMap.put("greatCount",greatCount);
            finalMap.put("badCount",badCount);
            finalMap.put("stuorteaId",map6.get("stuorteaId"));
            finalMap.put("courseId",map6.get("courseId"));
            finalMap.put("sumtime",sexpreLongList.get(i).get("sumtime"));
            finalMap.put("answercount",map2.get("answercount"));
            finalMap.put("problemcount",map2.get("problemcount"));
            finalMap.put("taskcount",map3.get("taskorexprecount"));
            finalMap.put("exprecount",map4.get("taskorexprecount"));
            finalMap.put("exprenotecount",map5.get("exprenotecount"));
            finalMap.put("userName",map6.get("userName"));
            finalMap.put("courseName",map6.get("courseName"));
            finalMap.put("preforSource",map6.get("preforSource"));
            finalMap.put("examSource",map6.get("examSource"));
            finalMap.put("sumSource",map6.get("sumSource"));
            finalMap.put("classId",map6.get("classId"));
            finalMap.put("className",map6.get("className"));
            list.add(finalMap);
        }
        return list;
    }

    /**
     * 学生统计详情--将结果拼接在一起
     */
    public List<Map<String,Object>> getStuDetailFinalList(List<Map<String,Object>> stuAndCouList, Map<String,Map<String,Object>> stuAllChapterSourceMap,
                                                          Map<String,Map<String,Object>> exporeAllLongMap,BigDecimal stuCount,
                                                          Map<String,Map<String,Object>> exporeLongMap){
        List<Map<String,Object>> list = new ArrayList<Map<String, Object>>();
        BigDecimal sumSource = new BigDecimal(0);
        BigDecimal sumLongTime = new BigDecimal(0);
        BigDecimal avgSource = new BigDecimal(0);
        BigDecimal avgLongTime = new BigDecimal(0);
        for (int i=0;i<stuAndCouList.size();i++){
            Map<String,Object> finalMap = new HashMap<String, Object>();
            //  取出map里需要的key
            String mapKey = String.valueOf(stuAndCouList.get(i).get("chapterNum"));
            Map<String,Object> map1= stuAllChapterSourceMap.get(mapKey);
            Map<String,Object> map2= exporeAllLongMap.get(mapKey);//实验总时长
            Map<String,Object> map3= exporeLongMap.get(mapKey);//每章节实验时长
            finalMap.put("className",stuAndCouList.get(0).get("className"));
            finalMap.put("courseName",stuAndCouList.get(0).get("courseName"));
            finalMap.put("userName",stuAndCouList.get(0).get("userName"));
            finalMap.put("taskSoruce",stuAndCouList.get(i).get("taskSoruce"));
            finalMap.put("stuorteaId",stuAndCouList.get(0).get("stuorteaId"));
            finalMap.put("chapterNum",stuAndCouList.get(i).get("chapterNum"));
            finalMap.put("chapterName",stuAndCouList.get(i).get("chapterName"));
            finalMap.put("usage_time",map3.get("usage_time"));
            //这个章节在这个班级的总成绩、
            sumSource = new BigDecimal(String.valueOf(map1.get("taskSoruce")));
            //这个章节在这个班级的总实验时长
            sumLongTime = new BigDecimal(String.valueOf(map2.get("sumusageTime")));
            if(sumSource.equals(new BigDecimal(0))||stuCount.equals(new BigDecimal(0))){
                avgSource = new BigDecimal(0);
            }else{
                //计算每章节的班级平均成绩
                avgSource = sumSource.divide(stuCount,2,BigDecimal.ROUND_HALF_UP);
            }
            if(sumLongTime.equals(new BigDecimal(0))||stuCount.equals(new BigDecimal(0))){
                avgLongTime = new BigDecimal(0);
            }else{
                //计算每章节的班级平均实验时长
                avgLongTime = sumLongTime.divide(stuCount,2,BigDecimal.ROUND_HALF_UP);
            }
            finalMap.put("avgSource",avgSource);
            finalMap.put("avgLongTime",avgLongTime);
            list.add(finalMap);
        }
        return list;
    }
}
